练习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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)