c - Allocating memory not working -
i'm trying allocate memory unsigned char* when pointer doesn't seem have been initialized!
unsigned char* split = (unsigned char*) malloc ((sizeof(unsigned char)*sizeof(unsigned int))); memset(&split,0,sizeof(int)); if(split==null) { std::cout<<"unable allocate memory!\n"; system("pause"); return 1; }
however every single time run error message. seems happen no matter data type use well!
your memset
call doesn't write buffer you've allocated, 1 pointed split
. writes area of memory split
variable stored - pointed &split
. whereupon split
becomes null
.
Comments
Post a Comment