分类: C/C++
2008-05-31 15:33:28
【C语言库函数源代码】
【本程序在Dev C++ 4.9.9.2 下编译通过】
/*
memmove() copies a source memory buffer to a destination memory buffer.This routine recognize overlapping buffers to avoid propogation.For cases where propagation is not a problem, memcpy() can be used.
memmove()由src所指定的内存区域赋值count个字符到dst所指定的内存区域。
*/
void * my_memmove(void * dst,const void * src,int count)
{
void * ret = dst;
if (dst <= src || (char *)dst >= ((char *)src + count))
{
while (count--)
{
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
}
else
{
dst = (char *)dst + count - 1;
src = (char *)src + count - 1;
while (count--)
{
*(char *)dst = *(char *)src;
dst = (char *)dst - 1;
src = (char *)src - 1;
}
}
return(ret);
}
int main()
{
char a[12];
puts((char *)my_memmove(a,"ammana_babi",16));
system("pause");
return 0;