Hi guys,
I've been driving myself crazy trying to figure out what's wrong here, so I thought I'd see if someone else might have a better idea.
Basically I'm reading from a file into a void pointer called inBuf, then trying to copy the data referenced by inBuf (and offset by a variable amount called sizeInBuf - but it isn't necessary for this example) into another void pointer called inTemp (code below). However, when I try a memcpy, my inTemp pointer remains blank. It could be that I'm missing something incredibly foolish, or it could be that it's 5:30am and I've been working on this for the last twelve hours or so. Anyway, I'd appreciate any help someone might be able to provide.
void *buffer = malloc(50000);
void *inTemp = malloc(10000);
char c;
read(infd, inBuf, 5000);
memcpy( &c, (char *) inBuf, 1 );
printf("char for inBuf: %s\n", &c);
memcpy( inTemp, (char *) buffer + sizeInBuf, 5000 );
memcpy( &c, (char *) inTemp, 1 );
printf("char for inTemp: %s\n", &c);
The result is:
char for inBuf: i
char for inTemp:
I'm certainly missing something here, but I would think that the first byte pointed to by inTemp should be the same as the first byte pointed to by inBuf - but as you can tell, it's not. inBuf returns 'i', but inTemp returns a null.
Any thoughts?
Thanks in advance!
Meeper