#include <stdio.h>
void main (){
char ch;
while ((ch=getchar())!='#'){
if ('\n'==ch)
continue;
switch(ch){
case 'a':
printf ("a\n");
break;
case 'b':
printf ("b\n");
break;
case 'c':
printf ("c\n");
break;
case 'd':
printf ("d\n");
break;
default:
break;
}
while (getchar() != '\n')
continue;
printf ("Please type a/b/c/c/d\n");
}
}
这段代码是在书上看到的,请问它是如何实现输入一行字符只读取首个字符。输入bcd,也只会打印b出来。
第二个while循环里面的
getchar()
吃掉了后面的字符。