c语言,哪里错了

[复制链接]
查看11 | 回复5 | 2008-9-5 22:23:18 | 显示全部楼层 |阅读模式
输入字符串,看是否有“d”。
#include
main()
{char str[100];
scanf("%s",str);
{int i=0;
while(!str)
{if(str=='d')
printf("yes");return;}
i++;}
printf("no");
}

回复

使用道具 举报

千问 | 2008-9-5 22:23:18 | 显示全部楼层
帮你修改了一下 你的代码有很多小问题 帮你注释了一下 #include main() {char str[100];scanf("%s",str);int i=0;while(str != '\0'){ if(str=='d') {
printf("yes");
return; } i++;}printf("no"); } while(str != '\0') 此处改为这样因为字符串的最后一位是以'\0'结束,你开始写的!str用得不太好,不能想当然,要明白语句的意思 ...
回复

使用道具 举报

千问 | 2008-9-5 22:23:18 | 显示全部楼层
帮你改完了~~错处真不少……#include main() { char str[100];scanf("%s",str);{int i=0; while(str!='\n') { if(str=='d') { printf("yes"); ...
回复

使用道具 举报

千问 | 2008-9-5 22:23:18 | 显示全部楼层
while(!str) 改为while('\0' != str)...
回复

使用道具 举报

千问 | 2008-9-5 22:23:18 | 显示全部楼层
void main { char str[100]; scanf("%s",str); int i=0; while(str) {if(str=='d') { printf("yes");return; } i++;} printf("no"); }...
回复

使用道具 举报

千问 | 2008-9-5 22:23:18 | 显示全部楼层
你printf("no")前应有else啊!...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行