编写一个程序,将两个字符串连接起来,要求:不能使用strcat函数。
说明:
(1)输入格式:gets()
(2)提示性文字输出格式:"input two strings:"
结果输出格式:"The new string is:%s\n"
#include <stdio.h>
int main()
{
int i,j,m,n;
char s1[40];
char s2[20];
printf("input two strings:");
gets(s1);
gets(s2);
i=j=0;
while(s1[i]!='\0') //检验数组位是否为空
i++; //不为空时,i+1
while(s2[j]!='\0') //检验数组位是否为空
{
s1[i]=s2[j]; //将第二个字符数组添加到第一个字符数组后面
i++;
j++;
}
s1[i]='\0';
printf("The new string is:%s\n",s1);
return 0;
}