您的位置:首页 > 其它

strcpy和memcpy函数的实现

2013-04-07 21:26 295 查看
strcpy函数的原型为:char *strcpy(char *strDest,const char *strSrc)

char *strcpy(char *strDest,const char *strSrc)

{

assert((strDest != NULL) && (strSrc != NULL));

char *address = strDest;

while((*strDest++ = *strSrc++) != '\0')

return 0;

retrun address;

}

memcpy函数原型:char *memcpy(char *to, const char *from, size_t size)

char *memcpy(char *to, const char *from, size_t size)

{

assert((to != NULL) && (from != NULL));

//防止to和from的地址发生改变

char *pto = to;

char *pfrom  = from ;

while(size-- > 0)

{

*pto++ = *from++;

}

return pto;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: