#include <stdio.h> #include <ctype.h> int main(int argc,char **argv) { char ch; printf("Enter the want you want:\n"); while((ch = getchar()) != ‘#‘) { if(ch == ‘\n‘) continue; //改成break的话,直接回车就会跳出循环。 if(islower(ch)) switch(ch) { case ‘a‘:puts("a");break; case ‘b‘:puts("b");break; case ‘c‘:puts("c");break; case ‘d‘:puts("d");break; default:printf("gameover.\n"); } else printf("simple.\n"); while(getchar() != ‘\n‘) //很经典的清空输入行 continue; printf("try again.\n"); } printf("bye.\n"); return 0; }
时间: 2024-10-08 10:28:56