Hi,
I have a char* buffer that is 1024 bytes in size, and am trying to write an int to a particular offset in the buffer, in this case 0, but all offsets have the same problem.
I initialize the buffer to some values when I first start up. For example, the first 8 bytes contain two separate ints, followed by 2 chars. When I print this out, it shows up as full.
However, when I try to add another value as shown in the code below, it completely destroys all the other data in the buffer.
char* buffer = new char[1024];
***buffer initialization code***
int fd = 4;
int bufferOffset = 0;
memcpy(buffer + bufferOffset, &fd, 4);
cout << buffer << endl;
Does anyone know why this could be happening? I'm under the impression that the above code should copy the 4 bytes of an int to my buffer, not completely destroy it.