1 #include <stdio.h> 2 #include <assert.h> 3 #include <stdlib.h> 4 5 void *memcpy( void * des, void const *src,size_t len); 6 void print( int *data,size_t n); 7 8 int main( void) 9 { 10 int des[ 11]; 11 int src[ 11]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 12 13 print(des, 10); 14 memcpy(des,src, sizeof(src)); 15 print(des, 10); 16 17 return 1; 18 } 19 20 void print( int *data, size_t n) 21 { 22 23 int i= 0; 24 printf( " \n "); 25 for(;i<n;i++) 26 printf( " %d ",data[i]); 27 28 printf( " \n "); 29 } 30 31 void *memcpy( void *des, const void *src,size_t len) 32 { 33 char * result =des; 34 const char * from = src; 35 assert(des&&src); 36 while(len--) 37 { 38 *(result++) = *( from++); 39 } 40 return des; 41 }