要求將輸入的兩個字符串連接起來。
#include
#include
char s1[80],s2[80];
int main()
{ void f();
printf("say sth:");
gets(s1);
printf("say sth. again:");
gets(s2);
f();
}
void f()
{ int i;
strcat(s1,s2);
for(i=0;i<=80;i++)
printf("%c",s1[i]);
}
#include <stdio.h>
char s1[80],s2[80];
void f(char *a, char * b)
{
char * a1 = a;
while (*a1 != '\0') a1++;
for (char * b1 = b; *b1 != '\0'; b1++,a1++)
{
*a1 = *b1;
}
*a1 = '\0';
}
int main()
{
printf("say sth:");
gets(s1);
printf("say sth. again:");
gets(s2);
f(s1,s2);
printf("%s",s1);
return 0;
}
say sth:hello
say sth. again: world
hello worldPress any key to continue