ok, I've gotten mem properly malloced, but I don't really understand what this is pointing to. *mem is pointing to a block of memory 256 bytes long, right? How do I put something in that memory? I.E., if I want the 245th byte to hold the hex "4a", how do I do that?
I've tried:
Code:
void *mem = malloc(256); // I think this is the right initialization
mem[245] = 71;
*mem[245] = 71;
(&mem)[245] = (void *)71; // gives warning without cast
mem += 245; // increments by 245*4 bytes. I think?
*mem = 71;
none of them work, and in fact all lines (except for those with comments) above give a warning and an error:
warning: derefrencing 'void *' pointer
error: invalid use of void expression
What is a valid use of a void expression?
Edit: Elysia, I am freeing 'mem', I just didn't put it in the above code. I was typing it in a hurry.
EDIT 2: Maybe I found my answer? Does this make sense to anyone:
Code:
void *mem = malloc(256);
int i = 0;
unsigned char *test;
for(i=0; i<256; i++) {
test = mem;
if(i==0) *test = 71;
printf("%p(%p), ", (mem)++, *test);