memcpy() vs memmove() in C
memmove() is very much like memcpy() but very flexible as it handles overlapping of memory blocks.
example :
char msg[50] = "abcdefghijklmnopqrstuvwxyz";
char temp[50];
main()
{
strcpy(temp, msg);
printf("Original Msg = %s\n",temp);
memcpy(temp+4, temp+16, 10);
printf("After memcpy without overlap = %s\n",temp);
strcpy(temp , msg);
memcpy(temp+6, temp+4, 10);
printf("After memcpy with overlap = %s\n",temp);
strcpy(temp, msg);
printf("Original Msg = %s\n",temp);
memmove(temp+4, temp+16, 10);
printf("After memmove without overlap = %s\n",temp);
strcpy(temp , msg);
memmove(temp+6, temp+4, 10);
printf("After memmove with overlap = %s\n",temp);
}
Original Msg = abcdefghijklmnopqrstuvwxyz
After memcpy without overlap = abcdqrstuvwxyzopqrstuvwxyz
After memcpy with overlap = abcdefefefefefefqrstuvwxyz
Original Msg = abcdefghijklmnopqrstuvwxyz
After memmove without overlap = abcdqrstuvwxyzopqrstuvwxyz
After memmove with overlap = abcdefefghijklmnqrstuvwxyz
Read more: http://wiki.answers.com/Q/Difference_between_memcpy_and_memmove_in_C_with_example#ixzz1JVBbVfSG
RELATED
0 COMMENT
No comment for this article.