用一段程序将两个字符串连接起来,不用strcat函数。求大神指点下

时间:2020.04.06 发布人:

用一段程序将两个字符串连接起来,不用strcat函数。求大神指点下

已解决问题

谷歌用户在2020.04.06提交了关于“大都会用一段程序将两个字符串连接起来,不用strcat函数。求大神指点下”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-12-17T22:14:01。

#include<stdio.h>

intmain()

{

chars1[80],s2[40];

inti=0,j=0;

printf("Pleaseinputthefirststring:");

scanf_s("%c",s1);

printf("\nPleaseinputthesecondstring:");

scanf_s("%c",s2);

while(s1[i]!='\0')

i++;

while(s2[j]!='\0'){

s1[i]=s2[j];

i++;

j++;

}

s1[i]=0;

printf("\nThenewstringis\t");

return0;

}


希望大家能够帮助她。

详细问题描述及疑问:

#include<stdio.h>

intmain()

{

chars1[80],s2[40];

inti=0,j=0;

printf("Pleaseinputthefirststring:");

scanf_s("%c",s1);

printf("\nPleaseinputthesecondstring:");

scanf_s("%c",s2);

while(s1[i]!='\0')

i++;

while(s2[j]!='\0'){

s1[i]=s2[j];

i++;

j++;

}

s1[i]=0;

printf("\nThenewstringis\t");

return0;

}


期待您的答案,滴水之恩,来日我当涌泉相报 !
希望以下的回答,能够帮助你。

第1个回答

用户名:whoami1978  

多个错,修改好的(含注释)参考

#include<stdio.h>

intmain()

{

chars1[8若聚鲁心该买结走活0],s2[40];

inti=0,j=0;

p来自rintf("Pleaseinputthefirststring:");

scanf_s("%s",s1,40)问答;//字串输入要用%s,不业背剂学顾用是%c

printf("\nPleaseinpu诗凯实输田贵温坏刻根tthesecondstring:");

scanf_s("%s",s2,40);//同上

while(s1[i]!='\0')

i条广刘工往夫静学待周洲++;

while(s2[j]!='\0')

{

s1[i]=s2[j];

i++;

j++;//你后面是全角的;了

}

s1[i]=0;

printf("\nThenewstringis:%s\n",s1);//你最终没有写变量

return0;

}

测试: