/*
my strcpy
@author arhaiyun
*/
#include<assert.h>
#include<string.h>
char* m_strcpy(char* dst, char* src)
{
//[1].Check to make sure it is valid
assert((dst != NULL) && (src != NULL));
char* ret = dst;
int length = strlen(src) + 1;
//[2].Make sure memory is not repeated
if(dst <= src || dst >= (src + length))
{
//[3].Copy '\0' in the end
while(length--)
{
*dst++ = *src++;
}
}
else
{
dst = dst + length - 1;
src = src + length - 1;
while(length--)
{
*dst-- = *src--;
}
}
//[4].return dst
return ret;
}
strcpy函数的实现
最新推荐文章于 2022-09-10 22:08:35 发布