回复 5楼 吹水佬
谢了
回复 6楼 see235959850
1.s1[5]后面没有‘\0',它无法作为一个字符位置被读入,所以需要自己添加使其成为一个完整的字符串2.字符串后面是自动加上'\0'的。
发表完毕。
程序代码:
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()
{
char c,str1[100],str2[100],str3[300];
int i,j;
printf("Please input the first string\nConfirm by Enter\n");
gets(str1);
printf("Please input the second string\nConfirm by Enter\n");
gets(str2);
for(i=0;(c=str1[i])!='\0';i++)
{
str3[i]=str1[i];
};
j=i;
for(i=0;(c=str2[i])!='\0';i++,j++)
{
str3[j]=str2[i];
};
str3[j] = '\0'; //添加'\0'
printf("The string which has been connected is:\n%s",str3);
getch();
}