C复制字符串

复制字符串函数可写为

char  *cpystr(char *from,char *to)
{
    char *addr=to;
    while (*to++=*from++);
    return addr;
}

测试代码为:

 1 #include <stdio.h>
2
#include <string.h>
3  char *cpystr(char *from,char *to);
4
5  int main()
6 {
7 char stra[]="abc";
8 char strtemp[3];
9 char *ptemp;
10 ptemp=pystr(stra,strtemp);
11 printf("%s\n",ptemp);
12 printf("%s\n",strtemp);
13 return 1;
14 }
15
16  char *cpystr(char *from,char *to)
17 {
18 char *addr=to;
19 while (*to++=*from++);
20 return addr;
21 }
原文地址:https://www.cnblogs.com/djcsch2001/p/2055905.html