我自己做的一道题,发生错误,希望大侠们帮忙分析
题:读取两个相同长度的字符串,分别存储在数组中,比较2个字符串,输出是否相等;不可用字符串头标string.h;#include<stdio.h>
#include<windows.h>
main()
{
char line1[100],character;
int c;
c=0;
printf("Enter first string\n");
do
{
character = getchar();
line1[c] = character;
c++;
}
while(character != '\n');
char line2[100],character2;
int b;
b=0;
printf("Enter the second string\n");
do
{
character2 = getchar();
line2[b] = character;
b++;
}
while(character2 != '\n');
int i;
i=0;
while(line1[i]==line2[i]&&line1[i]!='\0'&&line2[i]!='\0')
{i++;}
if(line1[i]=='\0'&&line2[i]=='\0')
printf("strings are equal\n");
else
printf("strings are not equal\n");
system("pause");
}
发生的错误是,不管我输入两个何种字符,输出都是strings are not equal。希望高人帮忙分析一下