#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void* my_memcopy(void* dest, void* rct, size_t num)
{
void* ret = dest;
while(num--)
{
if(rct > dest)
{
*(char*)dest = *(char*)rct;
(char*)dest++;
(char*)rct++;
}
else
{
*(char*)(dest+num) = *(char*)(rct+num);
}
}
return ret;
}
int main()
{
int arr1[] = {1,2,3,4,5,6,7,8,9,10};
//int arr2[20] = {0};
my_memcopy(arr1+3, arr1+1, 20);
int i = 0;
for(i = 0; i < 10; i ++)
printf("%d ",arr1[i]);
return 0;
}
my memcpy 编写,解决复制过程中覆盖问题
于 2022-03-21 17:31:37 首次发布