|
-
Jan 4th, 2008, 01:39 AM
#1
Thread Starter
PowerPoster
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.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|