参考网址:
什么?面试官让我写strcpy()函数_m0_57304511的博客-CSDN博客
strpy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include<stdio.h> #include<assert.h> char * my_strcpy(char* dest, const char* src)
{ assert( dest && src ); char* ret = dest; while(*dest++ = *src++) { ; } return ret; } int main() { char arr1[20] = { 0 }; char arr2[] = "hello"; printf("%s\n", my_strcpy(arr1, arr2)); return 0; }
|
mempy
1 2 3 4 5 6 7 8 9 10
| void * memcpy(void *dest, const void *src, unsigned int count); { if ((src == NULL) || (dest == NULL)) return; while (count--) *dest++ = *src++; return dest; }
|