//不用库函数实现memcpy #include <stdio.h> #include <assert.h> void * my_memcpy ( void *dst, void const *src, int count ) { void * ret = dst; assert( ( dst != NULL ) && ( src != NULL )); while( count-- ) { *( ( char * )dst ) = *( ( char * )src ); ( ( char * )dst )++; ( ( char * )src )++; } *( ( char * )dst ) = '\0'; return ret; } int main() { char dst[] = "shiqinianchan"; char *src = "dandanwa"; my_memcpy( dst, src, 8); printf("内存拷贝后的结果是:%s\n",dst); return 0; }
时间: 2024-10-03 04:53:28