C语言:将两个字符串连接起来。

【程序】
#include <stdio.h>
int main()
{
char s1[80],s2[40];
int i=0,j=0;
printf("\nInput the first string:");
scanf("%s",s1);
printf("\nInput the second string:");
scanf("%s",s2);
while (s1[i] !='\0')
______1______;
while (s2[j] !='\0')
______2______; /* 拼接字符到s1 */
s1[i] ='\0';
printf("\nNew string: %s",s1);
}

请补充

#include <stdio.h>
int main()
{
char s1[80],s2[40];
int i=0,j=0;
printf("\nInput the first string:");
scanf("%s",s1);
printf("\nInput the second string:");
scanf("%s",s2);
while (s1[i] !='\0')
i++;
while (s2[j] !='\0')
s1[i++]=s2[j++]; /* 拼接字符到s1 */
s1[i] ='\0';
printf("\nNew string: %s",s1);
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-20
void main()
{
void con(char sting1[],char sting2[],char sting3[]);
char s1[20],s2[20],s3[40];

printf("Input sting1: ");
scanf("%s",s1);
printf("Input sting2: ");
scanf("%s",s2);
con(s1,s2,s3);
printf("%s\n",s3);
}
void con(char sting1[],char sting2[],char sting3[])
{
int i,j;
for(i=0;sting1[i]!='\0';i++)//////////////////////////多个分号
sting3[i]=sting1[i];

for(j=0;sting2[j]!='\0';j++)//////////////////////////多个分号
sting3[i+j]=sting2[j];
sting3[i+j]='\0';
}
另外,站长团上有产品团购,便宜有保证
第2个回答  2020-05-12
这些是宏的功能。#是将一个参数转换为字符串。##可以连接字符串 比如这样:#include
<stdio.h>
#define
STR(a,b)
a##bint
main()
{ printf("%s
",STR("123","456"));
return
0;
}
第3个回答  2011-04-18
i++; 1
s1[i] = s2[i];
相似回答