当前位置: 代码迷 >> 综合 >> C程序设计语言 5-3
  详细解决方案

C程序设计语言 5-3

热度:21   发布时间:2024-01-20 04:15:23.0

练习5-3 用指针方式实现第2章中的函数strcat。函数strcat(s, t)将t指向的字符串复制到s指向的字符串的尾部。 

#include <stdio.h>int my_strcat(char *, char *);int main()
{char s[20], t[10];printf("please input string s, while s has no more than 10 chars.\n");scanf("%s", s);printf("please input string t, while t has no more than 10 chars.\n");scanf("%s", t);my_strcat(s, t);printf("concatenated string:%s\n", s);return 1;
}int my_strcat(char *s, char *t)
{//int i = 0, j = 0;while (*s++ != '\0');s--;while ((*s++ = *t++) != '\0');return 1;
}