Dear all,
I'm writing a program for a project that revolves around the need to dynamically allocate a big chunk of memory. But for whatever reason, and despite much searching, reading the relevant chapters in the books I have, I am still unable to do something as easy as setting the value of a char in the memory allocated. For example:
This prints an upside down question mark - not what I expected!
Any ideas on what stupid thing I'm doing?
Many thanks,
David
I'm writing a program for a project that revolves around the need to dynamically allocate a big chunk of memory. But for whatever reason, and despite much searching, reading the relevant chapters in the books I have, I am still unable to do something as easy as setting the value of a char in the memory allocated. For example:
Code:
int main(int argc, const char * argv[])
{
unsigned char* ptr;
ptr = calloc(1000, sizeof(char));
*ptr = 0;
*(ptr+1) = 1;
*(ptr + 2) = 2;
*(ptr + 3) = 3;
printf("%c" , *(ptr + 2) );
return 0;
}
This prints an upside down question mark - not what I expected!
Any ideas on what stupid thing I'm doing?
Many thanks,
David