下面是一个简单的c语言程序,但运行时出了问题,具体描述在下方。恳请各位大佬帮忙解答一下。 - 爱问答

(爱问答)

下面是一个简单的c语言程序,但运行时出了问题,具体描述在下方。恳请各位大佬帮忙解答一下。

为什下面这个程序运行时输入a,按下【enter】没动静,但是再按下【enter】后显示I recognize only lowercase letters.  怎么才能让程序按照我的语气执行case a中的语句呢?#include<stdio.h>#include<ctype.h>int main(void){ char ch;  printf("Give me a letter of the alphabet,and I will give"); printf("an animal name beginning with that letter. "); printf("please type in a letter;type to end my act. "); while(ch=getchar()!='#') {    if(' '==ch)  continue;  if(islower(ch))  switch(ch)  {   case 'a':    printf("argali,a wild shhep of Asia ");    break;   case 'b':    printf("babirusa,a  wild pig of Malay ");    break;   case 'c':    printf("coati,racoonlike mamal ");    break;   case 'd':    printf("desman,aquatic,molelike critter ");    break;   case 'e':    printf("echidina,the spiny anteater ");    break;   case 'f':    printf("fisher,brownish marten ");    default:     printf("That's a stumper");      }//swich结构结束,但while循环仍在继续  else   printf("I recognize only lowercase letters. ");  while(getchar()!=' ')  continue;  }//while循环结束 printf("Bye! ");  return 0;  }

你的

while(ch=getchar()!='#')

不正确(注意运算符优先级)

正确的

while((ch=getchar())!='#')


相关标签:c语言

下一篇:请问java开发中的软件环境、硬件环境都有什么?

上一篇:VB怎么用if语句和getsetting语句查找注册表,求大神解答,谢谢。

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?