Tag: c; memory copy function
/************************************************************************************1. Simulation implements the implementation of the Memmove function. (consider memory overlap) ************************************************************************************/#include < stdio.h> #include <string.h> #include <assert.h>void * my_memmove (void *aim,const void *source,int length) {Int i = 0;void *p = aim;assert (aim& &source);if (((char*) aim - (char*) source)//memory overlap from back to forward copy >= 0 ({for length-1; i >=0; i--) {* ((char *) aim + i*sizeof (char)) = * (( char *) source + i*sizeof (char));} return (P);} else //non-overlapping normal copy {for (i = 0; i <length; i++) {* ((char *) aim + i*sizeof (char)) = * ((char *) source + i*sizeof (char));} return (P);}} // 1 2 3 4 5&nbSp;6 7 8 9 0 0 // *0*1*2*3*4*5*6*7*8*9*10 //1 2 3 4 5 6 7 8 9 0 0int main () {int arr[11] = { 1, 2 , 3, 4, 5, 6, 7, 8, 9, 0 };int i = 0;my_memmove ( arr, arr , 36);for (i; i < 11; i++) printf ("%d\n", Arr[i]);/*for (i = 0; i < 10;i++) printf ("%d\n", * ( (int * ) My_memmove (arr, arr+1, 36) +1); */return 0;}
C language itself implement memory copy function Memmov ()