#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
void *MyMemmove(void *str1, void *str2, int count)
{
assert(str1 != NULL&&str2 != NULL);
if (str1 < str2)
{
while (count--)//从前往后赋值
{
*(char *)str1 = *(char *)str2;
((char *)str1)++;
((char *)str2)++;
}
}
else
{
while (count--)//从后往前赋值
{
*((char *)str1 + count) = *((char *)str2 + count);
}
}
}
int main()
{
int i = 0;
int str1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
MyMemmove(str1 + 2, str1, 16);
for (i = 0; i < 9; i++)
{
printf("%d ", str1[i]);
}
printf("\n");
system("pause");
return 0;
}
模拟memmove
最新推荐文章于 2024-07-25 10:43:06 发布
1181

被折叠的 条评论
为什么被折叠?



