- #include<stdio.h>
- #include<ctype.h>
- int main(void){
- char ch;
- printf("Enter a word # to stop\n");
- while((ch = getchar()) != '#'){
- if(ch == '\n'){
- continue;
- }
- if(islower(ch)){
- switch(ch){//swith表达式应该具有整数值
- case 'a'://case标签必须是整型、常量或者整数常量表达式。不能使用变量
- printf("a");
- break;
- case 'b':
- printf("b");
- break;
- case 'c':
- printf("c");
- break;
- default:
- printf("else");
- break;
- }
- }
- else{
- printf("we need a lower!");
- }
- while(getchar() != '\n')//只读取一行中的首字母
- continue;//跳过输入行的剩余部分
- printf("try again!\n");
- }
- return 0;
- }
转载于:https://blog.51cto.com/fanaticssk/826119