void main()
{
int num
char ch
scanf("%c %d",&ch,&num)
switch(ch)
{
case 'A'://你的switch中判断的损失字符
printf("你输入的是字符A\n")
}
switch(num)
{
case 9://你的switch中判断的是数组
printf("你输入的是数字9\n")
}
}
//总结:你的case 中的类型要和switch中的类型相对应
C语言中没有when,与case搭配使用的是switch。switch......case是C语言中一种选择匹配命令。
下面通过具体的实例来说明其用法:
int a=2, bswitch(a)
{
case 0 : // 如果a=0,执行该case中的语句
{
b = a
break
}
case 1 : // 如果a=1,执行该case中的语句
{
b = a+1
break
}
case 2 : // 如果a=2,执行该case中的语句
{
b = a+2
break
}
default: // 如果a与上面所以case后面的值都不相等,执行default中的语句
b = 0
}