/*
* switch - case 的2个知识点
* 1.default:位置随便 都可以
* 2.case 可以为一个范围 ,2变量中间用3个点表示,前后有空格
*/
#include
int main()
{
/*
int grade;
while (1) {
printf("Please input a number:(-1 to quit)\n");
scanf("%d", &grade);
switch (grade) {
case -1:
return 0;
default:
printf("default:\n");
break;
case 1 ... 100:
printf("1-100\n");
break;
case 101:
printf("10\n");
break;
}
}
*/
char c;
while (1) {
printf("Please input a character:(when it is neither letters nor numbers then quit)\n");
while (!isprint((c = getchar()))) {
(void)0;
}
switch (c) {
default:
printf("default quit!\n");
return 0;
case 'a' ... 'z':
printf("%c in a-z\n", c);
break;
case 'A' ... 'Z':
printf("%c in A-Z\n", c);
break;
case '0' ... '9':
printf("%c in 0-9\n", c);
break;
}
}
return 0;
}
阅读(2108) | 评论(0) | 转发(1) |