Hi guys!
I have a problem with memcpy. I have a memory location with 3 strings, all 0 terminated and want to shorten it to 2 strings.
Example:
And my code:Code:Tree\0House\0Banana\0
becomes
House\0Banana\0
tmp = a char array where House\0Banana\0 should be saved temporarilyCode:void msgbox(char text[]){MessageBox(NULL,text,"Debug",MB_OK);}
char msgbuf[200];
memcpy(tmp, startnewstring, newlength);
if((worktodo = realloc(worktodo, newlength!=0?newlength:1)) == NULL) break;
memcpy(worktodo, &tmp, newlength);
sprintf(msgbuf, "newlength: %d, startnewstring: %d, tmp: %s, worktodo: %s", newlength, startnewstring, tmp, worktodo);
msgbox(msgbuf);
startnewstring = the memory location of House\0 (= memory location of Tree\0 + 5)
newlength = the length in bytes of House\0Banana\0
worktodo = the array that holds Tree\0House\0Banana\0 and should become House\0Banana\0
It seems the memory copying into tmp is successful but the copying back into the new worktodo is not.
That's what I get:
Why is there gibberish in worktodo?Code:---------------------------
Debug
---------------------------
newlength: 13, startnewstring: 13319336, tmp: House, worktodo: °=Ë
---------------------------
OK
---------------------------
TIA, Hawk