2
我使用memmove()
,但似乎目的地覆蓋源或也許我不明白是什麼重寫。我有char
(目的地)的數組,然後一個指針到目的地,即所述載體內。memmove與overlaping
char destination[]="abcdefg";
char * source = destination+3;
來源是"defg"
。然後我使用memmove()
移動四個字符並打印源文件。當我查看源代碼時,它已更改爲"gefg"
。
printf("%s\n",memmove(destination,source,sizeof(char)*4));
printf("%s",source);
我以爲memmove()
應該防止覆蓋,或者我不理解。
也許你應該看看目的地,而不是在源(這仍然是什特+ 3)。 (注:'的sizeof(char)的'是1,根據定義) – wildplasser
'memmove'意味着複製字節即使區域重疊 –
是的,我很抱歉,是覆蓋不重疊。 –