If I create a void pointer, and malloc a section of memory to that void pointer, how can I print out the individual bits that I just allocated?
For example:
void print_memory(void *ptr, int size)
{ // Print 'size' bytes starting from 'ptr'
unsigned char *c = (unsigned char *)ptr;
int i = 0;
while(i != size)
printf("%02x ", c[i++]);
}
As H2CO3 mentioned, using uninitialized data results in undefined behavior, but the above snipped should do what want. Call:
print_memory(p, 24);