由键盘任意输入两个字符串,连接字符串2到字符串1,输出连接后的字符串1

不用到strcat函数和指针,用数组和循环语句知识写,也不涉及函数的知识,谢谢!,小弟我初学C语言,不用那复杂的

路过,看没人理你我帮你解决吧!!
#include <stdio.h>
main()
{
char s1[80],char s2[40];
int i=0,j=0;
printf("\n input string1:");//提示你输入字符串1
scanf("%s",s1);
printf("\n input string2:");//提示你输入字符串2
scanf("%s",s2);
while(s1[i]!='\0')
i++; //直到遇到s1的结束符为止
while(s2[j]!='\0')
s1[i++]=s2[j++];//将s2复制到s1后面
s1[i]='\0';//添加字符串结束标志
printf("\n New string is :%s",s1);

}
是不是你要的答案?也可用for循环写,自己努力哦,加油!!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-05-18
#include "stdio.h"
void main()
{
char s1[100],s2[100];
int i,j;
printf("Input 2 string:\n");
scanf("%s",s1);
scanf("%s",s2);
i=0;
while(s1[i]!='\0')
i++;
for(j=0;s2[j]!='\0';j++)
{
s1[i]=s2[j];
i++;
}
s1[i]='\0';
printf("The result is:\n%s\n",s1);
}
第2个回答  2020-06-13
那么麻烦啊几行代码就完事了:
#include
<stdio.h>
int
main()
{
char
des[100];
char
src[50];
scanf("%s%s",des,src);
char*
index1
=
des,*index2
=
src;
while
(*index1
!=
'\0')
index1++;
while
(*(index1++)
=
*(index2++));
printf("%s",des);
return
0;
}
再给你写个函数:
char*
Strcat(char*
des,
char*
src)
{
if
(*src=='\0')
return
des;
char*
index
=
des;
while
(*index
!=
'\0')
index++;
while
(*index++
=
*src++);
return
des;
}
第3个回答  2018-05-06
这是个比较简单的程序
#include<stdio.h>
#include<string.h>
int main(void)
{

char a[80],b[80];
gets(a);
gets(b);
strcat(a,b);||"strcat"是连接函数,表示把字符串b连在a上,
puts(a);
return 0;
}
第4个回答  2008-05-18
老兄啊 你有这个时间自己就写出来了啊
而且连个分都不给
相似回答