Null pointkr assiknment是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:14:16
我在运行一个C程序:
#include “stdio.h”
main()
{ static char str[ ]={‘h’,‘e’,‘l’,‘l’,‘o’};
char str1[ 5 ];
int flag,i ;
for (i =0; i <5;i++)
scanf(“%c”,str1[i]);
flag=0;
for(i=0;i<5;i++)
if (str1[5]==str[5])
flag=1;
if(flag)
printf(“This word is not hello” );
else
printf(“This word is hello” );
}
后结果带有出现该语句,请问哪位高手为什么会出现此情况?
同时问我能否倒数第六行的flag=1变为{flag=1;break;}?为什么?

你比较的地方逻辑有错误,当然可以变成{flag=1;break;}
修改正确如下:
#include "stdio.h"
main()
{ static char str[ ]={'h','e','l','l','o'};
char str1[ 5 ];
int flag,i ;
gets(str1);
flag=0;
for(i=0;i<5;i++)
if (str1[i]!=str[i])
{flag=1;break;}
if(flag)
printf("This word is not hello");
else
printf("This word is hello");
}

scanf(“%c”,str1[i]);改为scanf(“%c”,&str1[i]);