主题:一道题关于switch
输入一个字符,如果是数字输出1;如果是大写字母则输出2;如果是小写字母输出3;如果是空格则输出4;如果是回车换行符号则输出5;是其他符号输出6.
main()
{
char c;
scanf("%c",&c);
switch(c)
{
case '0'<=c&&c<='9':printf("c=%\n",'1');break;
case 'A'<=c&&c<='Z':printf("c=%\n",'2');break;
case 'a'<=c&&c<='z':printf("c=%c\n",'3');break;
case c==' ': printf("c=%c\n",'4');break;
case c=='\n': printf("c=%c\n",'5');break;
default: printf("c=%c\n",'6');break;
}
}
以下是错误信息:C:\Users\Administrator\Desktop\p50_3-10.c(8) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(9) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(10) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(11) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(12) : error C2051: case expression not constant
Error executing cl.exe.
p50_3-10.exe - 5 error(s), 0 warning(s)
main()
{
char c;
scanf("%c",&c);
switch(c)
{
case '0'<=c&&c<='9':printf("c=%\n",'1');break;
case 'A'<=c&&c<='Z':printf("c=%\n",'2');break;
case 'a'<=c&&c<='z':printf("c=%c\n",'3');break;
case c==' ': printf("c=%c\n",'4');break;
case c=='\n': printf("c=%c\n",'5');break;
default: printf("c=%c\n",'6');break;
}
}
以下是错误信息:C:\Users\Administrator\Desktop\p50_3-10.c(8) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(9) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(10) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(11) : error C2051: case expression not constant
C:\Users\Administrator\Desktop\p50_3-10.c(12) : error C2051: case expression not constant
Error executing cl.exe.
p50_3-10.exe - 5 error(s), 0 warning(s)