c语言,哪里错了

来源:百度知道 编辑:UC知道 时间:2024/04/29 06:18:21
输入字符串,看是否有“d”。
#include<stdio.h>
main()
{char str[100];
scanf("%s",str);
{int i=0;
while(!str[i])
{if(str[i]=='d')
printf("yes");return;}
i++;}
printf("no");
}

帮你改完了~~错处真不少……
#include<stdio.h>
main()
{
char str[100];
scanf("%s",str);
{
int i=0;
while(str[i]!='\n')
{
if(str[i]=='d')
{
printf("yes");
return;
}
i++;
}

}
printf("no");
}
你错的地方是while(!str[i]) 不能这样写
还有i++应该在while循环里面……
还有printf和return 应该用大括号括起来,不然无论if里的判断正确与否都会执行return

void main
{
char str[100];
scanf("%s",str);
int i=0;
while(str[i])
{if(str[i]=='d')
{
printf("yes");return;
}
i++;}
printf("no");
}

while(!str[i])
改为
while('\0' != str[i])

帮你修改了一下
你的代码有很多小问题
帮你注释了一下

#include<stdio.h>
main()
{
char str[100];
scanf("%s",str);
int i=0;
while(str[i]