输入两个字符串s和t,将字符串s连接到字符串t的尾部,再输出字符串t。要求定义和调用strc(s,t)完成字符串的连接。
#include <stdio.h>
void strc(char *s, char *t);
int main(void)
{
char s[80], t[80];
printf("Enter s: ");
gets(s);
printf("Enter t: ");
gets(t);
strc(s, t);
puts(t);
return 0;
}
void strc(char *s, char *t)
{
while (*t != '\0'){
t++;
}
while ((*t =*s) != '\0'){
t++;
s++;
}
}
本题主要练习自定义函数和指针的使用。
应注意指针的移动和自定义函数的形参形式。
输出参考: