Overwrite avoiding in memcpy
Hi all,
First I create a dynamic buffer and set all element to zero. Then add a int value first to the buffer. Then after that int value add a string to the buffer, actually at the end of int value. But seems my code overwrite each other.
Here is the code,
Code:
char* tmpBuffer = new char[10];// Dynamic allocation
::memset(tmpBuffer, 0, 10);
::memcpy(tmpBuffer, &iReq, 4);
::memcpy(tmpBuffer, &strGetName, 6);
How can I avoid this issue.
Re: Overwrite avoiding in memcpy
Ok, I go it in this way.
Code:
::memcpy(&tmpBuffer[0], &iReq, 4);
::memcpy(&tmpBuffer[4], &strGetName, 6);