转载原文地址:http://blog.csdn.net/xiaoxieqingfa/article/details/8022287
#include <assert.h>
#include <iostream>
using namespace std;
//用循环实现
char *mystrcpy(char *dest,const char *src)
{
assert(dest!=NULL&&src!=NULL);
char *p=dest;
while((*dest++=*src++)!='\0');
return p;
}
//不用循环实现
char *mystrcpy_NR(char *dest,const char *src)
{
if((*dest=*src)=='\0')
return dest;
else
mystrcpy_NR(++dest,++src);
}
int main()
{
char *str="abcdefghijklmn";
char ss[100]= {'0'};
char sss[100]= {'0'};
mystrcpy(ss,str);
printf("strcpy loop:\n");
printf(ss);
printf("\nstrcpy nonloop:\n");
mystrcpy_NR(sss,str);
printf(sss);
return 0;
}