Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209684
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: C/C++

2011-03-21 20:06:36

  1. /* k&r(5.5): Character Pointers and Functions
  2.    created on Mar 21, 2011
  3.  */
  4. #include "stdio.h"
  5. #define MAX 1000
  6. void astrcpy(char *, char *);
  7. void pstrcpy(char *, char*);
/* main: copy of  two strings */
  1. int main()
  2. {
  3.     char ps[] = "Hello Mark";
  4.     char pt[MAX];

  5.     pstrcpy(pt, ps);
  6.     printf("%s\n", pt);
  7.     return 0;
  8. }

  9. /* strcpy: copy t to s; array subscript version */
  10. void astrcpy(char *s, char *t)
  11. {
  12.     int i;

  13.     i = 0;
  14.     while((s[i] = t[i]) != '\0')
  15.      i++ ;
  16. }

  17. /* strcpy: copy t to s; pointer version */
  18. void pstrcpy(char *s, char *t)
  19. {
  20.     while ((*s++ = *t++))
  21.     ;
  22. }
阅读(286) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~