首页 > 电脑

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

更新时间2018-03-06 19:45:54

为什下面这个程序运行时输入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语言

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

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