Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2794755
  • 博文数量: 471
  • 博客积分: 7081
  • 博客等级: 少将
  • 技术积分: 5369
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-04 21:55
文章分类

全部博文(471)

文章存档

2014年(90)

2013年(69)

2012年(312)

分类: C/C++

2012-08-17 10:10:33


点击(此处)折叠或打开

  1. #include
  2. #include

  3. /*
  4. 等价于
  5. void stringcopy(char *source, char *target)
  6. {
  7.     int i=0;
  8.     while((source[i] = target[i]) != '\0')
  9.         i++;
  10. }
  11. */
  12. void strcpy(char * source,char * des)
  13. {
  14.     
  15.     while(*des++ = *source++);//先赋值再自增
  16. }


  17. void strcat(char * from,char * to)
  18. {
  19.     while(*from)
  20.         from++;
  21.     while(*from++=*to++);
  22.     
  23. }
  24. int main()
  25. {
  26.     char str_a[] = "Welcome to ";
  27.     char str_b[] = "";
  28.     strcpy(str_a,str_b);
  29.     printf("%s\n",str_b);

  30.     char str_c[]="hello ";
  31.     char srr_d[]="world!";
  32.     strcat(str_c,srr_d);
  33.     printf("%s\n",str_c);

  34.     return 0;
  35. }

  36. Welcome to
  37. hello world!
  38. Press any key to continue

阅读(648) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~