I have a question about pointers. I want to take the address stored in a pointer and store it in an unsigned char... yeah, it's not big enough, i know, but it works for what im doing i think. Only problem is, everything I try yields the wrong result. I have two variables, ip and main_mem, both unsigned chars:
and then I tried:
*ip = (unsigned char *) *main_mem + 1;
So if this doesn't work, how do i do it? If more source is needed or if anyone wants an explanation, let me know. Thanks guys!!!
memcpy ((unsigned char *) ip, (unsigned char *) main_mem);
Aside from it being a stupid thing to do, this should work:
You could also, if you want to use memcpy() do:
unsigned char c;
c = (unsigned char)p;
However, depending on the byte-ordering (little endian or big endian) you may get "the wrong end" of the pointer that way.
memcpy(&c, p, sizeof(unsigned char));