Copies n characters of the source buffer into the destination buffer, even if the regions overlap.
Include
<string.h>
Prototype
void *memmove(void *s1, const void *s2, size_t
n);
Arguments
s1s2nReturn Value
Returns a pointer to the destination buffer.
Remarks
If the buffers overlap, the effect is as if the characters are read first
from s2, then written to s1, so the buffer is not
corrupted.
Example
#include <string.h>
#include <stdio.h>
int main(void)
{
char buf1[50] = "When time marches on";
char buf2[50] = "Where is the time?";
char buf3[50] = "Why?";
printf("buf1 : %s\n", buf1);
printf("buf2 : %s\n", buf2);
printf("buf3 : %s\n\n", buf3);
memmove(buf1, buf2, 6);
printf("buf1 after memmove of 6 chars of "
"buf2: \n\t%s\n", buf1);
printf("\n");
memmove(buf1, buf3, 5);
printf("buf1 after memmove of 5 chars of "
"buf3: \n\t%s\n", buf1);
}
Example Output
buf1 : When time marches on
buf2 : Where is the time?
buf3 : Why?
buf1 after memmove of 6 chars of buf2:
Where ime marches on
buf1 after memmove of 5 chars of buf3:
Why?