字符串连接返回串尾

1612阅读 0评论2011-05-20 onezeroone
分类:C/C++


  1. #include <stdio.h>
  2. #include <string.h>

  3. char *myStpcpy(char *des, const char *src);

  4. int
  5. main(void)
  6. {
  7.     char res[20];
  8.     char *to = res;
  9.     to = myStpcpy(to, "hello");
  10.     to = myStpcpy(to, " world\n");

  11.     printf(res);

  12.     return 0;
  13. }

  14. char *
  15. myStpcpy(char *des, const char *src)
  16. {
  17.     if (NULL == des || NULL == src)
  18.         return NULL;

  19.     char *d = des;
  20.     const char *s = src;

  21.     do
  22.         *d++ = *s;
  23.     while (*s++ != '\0');

  24.     return (d - 1);
  25. }

上一篇:判断点与三角形的关系
下一篇:未知个数的字符串连接