孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

复制字符串函数可写为

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 }
posted on 2011-05-24 19:55  孤独的猫  阅读(233)  评论(0编辑  收藏  举报