C语言:模拟实现strcmp
程序员文章站
2022-05-13 17:35:09
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#i...
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<assert.h> void *my_memmove(void *p1, void *p2, size_t count) { assert(p1); assert(p2); char *dest = (char *)p1; char *src = (char *)p2; dest = dest + 16; src = src + 8; if ((src < dest) && (dest < src + count)) { while (count--) { *(dest + count) = *(src + count); } } else { while (count--) { *dest = *src; src++; dest++; } } return p2; } int main() { int arr1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int i = 0; int len = sizeof(arr1) / sizeof(arr1[0]); int *ret = my_memmove(arr1, arr1, 16); for (i = 0; i < len; i++) { printf("%d ", *(ret + i)); } system("pause"); return 0; }