程序代码:
#include <stdio.h> #include <string.h> int main(void) { char* key = "TSW", *ans; char* token[] = {"老师","学生","工人"}; while ((ans = strchr(key, getchar())) != NULL) { printf("欢迎您,%s!\n请继续输入:", token[ans - key]); getchar(); } return 0; }
try this!
#include<stdio.h> #include<string.h> int main(void) { char ch; while(1) { ch=getch(); switch(ch) { case 'T': puts("欢迎您,老师!");break; case 'S': puts("欢迎您,学生!");break; case 'W': puts("欢迎您,工人!");break; default : exit(0); } } return 0; getch(); }