Possible Duplicate:
Problem when copying memory
(tuple1 and tuple2 are void pointers passed to this function)
char *data;
data = (char*) calloc (84, 1);
memcpy(data, tuple1, 44);
memcpy(data+44, tuple2, 40);
I have allocated 84 bytes for data. I am doing the first memory copy memcpy(data, tuple1, 44); which copies 44 bytes from the address of tuple1 to the address of data and when I try to read data it turns out that it had copied the bytes of tuple1 on the first 44 bytes of data and then it had copied again the 44 bytes of tuple1 until it has filled the 84 bytes allocated for data.
When I do the second memory copy I try to paste the 40 bytes of tuple2 44 bytes after the address of data. In reality it does the same thing as with tuple1 and even more - it starts pasting from the address of data and not 44 bytes after the address of data.
Why is that?! And how can I prevent it? Anyone help, I'm very desperate.