#include<stdio.h>
char *strcpy(char *strdest, char *strsrc)
{
if((strdest == NULL)||(strsrc == NULL))
{
return NULL;
}
char *strdestcopy = strdest; //保存目标字符串的首地址
while(*strsrc!=’\0’) //等价于 while((*strdest++=*strsrc++)!=’\0’)
{
*strdest = *strsrc;
strsrc++;
strdest++;
}
*strdest = ‘\0’;
return strdestcopy;
}
int getstrlen(const char * strsrc)
{
int len = 0;
while(*strsrc++ != ‘\0’)
{
len++;
}
return len;
};
int main()
{
char strsrc[] = “hello world!”;
char strdest[20];
int len = 0;
len = getstrlen(strcpy(strdest,strsrc));
printf(“strdest: %s\n”,strdest);
printf(“length of strdest:%d\n”,len);
return 0;
}