请教,switch case 用法
我这个习题代码里面使用switch case 标签却编译出来全部都有问题。难道switch只能和while()一起使用?求高人回答下。
-------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.c
D:\学习\code\c.c(26) : error C2043: illegal break
D:\学习\code\c.c(27) : error C2046: illegal case
D:\学习\code\c.c(29) : error C2043: illegal break
D:\学习\code\c.c(30) : error C2046: illegal case
D:\学习\code\c.c(32) : error C2043: illegal break
D:\学习\code\c.c(33) : error C2046: illegal case
D:\学习\code\c.c(35) : error C2047: illegal default
D:\学习\code\c.c(35) : error C2043: illegal break
Error executing cl.exe.
c.exe - 8 error(s), 0 warning(s)
#include <stdio.h>
int hs0(int *);
void hs1(void);
void hs2(void);
int main(void)
{
int sr;
while((scanf("%d", &sr)) != EOF)
{
printf("Please choose one of the following;\n"
"1)copy files" " " "2)move files\n"
"3)remove files"" ""4)quit\n");
hs0(&sr);
}
}
int hs0(int * a)
{
if(*a > 0 && *a < 5)
{
switch(*a)
case '1':
hs1();
break;
case '2':
hs2();
break;
case '3':
printf("Hello3\n");
break;
case '4':
printf("Hello4\n");
default : break;
}
else
printf("输入错误请对照菜单重新输入\n");
}
void hs1(void)
{
printf("功能成功\n");
}
void hs2(void)
{
printf("功能成功\n");
}
-------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.c
D:\学习\code\c.c(26) : error C2043: illegal break
D:\学习\code\c.c(27) : error C2046: illegal case
D:\学习\code\c.c(29) : error C2043: illegal break
D:\学习\code\c.c(30) : error C2046: illegal case
D:\学习\code\c.c(32) : error C2043: illegal break
D:\学习\code\c.c(33) : error C2046: illegal case
D:\学习\code\c.c(35) : error C2047: illegal default
D:\学习\code\c.c(35) : error C2043: illegal break
Error executing cl.exe.
c.exe - 8 error(s), 0 warning(s)
...全文
相关推荐
switch-case语句用法
if语句处理两个分支,处理多个分支时需使用if-else-if结构,但如果分支较多,则嵌套的if语句层就越多,程序不但庞大而且理解也比较困难.因此,C语言又提供了一个专门用于处理多分支结构的条件选择语句,称为switch语句,又称开关语句.
c#中switch case的用法实例解析
主要介绍了c#中switch case的用法实例解析,对于C#的初学者来说有必要熟练掌握,需要的朋友可以参考下
js switch case default 的用法示例介绍
switch case default的用法应该存在一部分人不会使用吧,其实很简单就是每个case后,一定要加:break;default,就相当于else,不会的朋友可以了解下
举例讲解Swift编程中switch...case语句的用法
主要介绍了Swift编程中switch...case语句的用法,其中fallthrough关键字在switch语句中的使用是重点,需要的朋友可以参考下
详解Swift的switch...case语句中break关键字的用法
主要介绍了Swift的switch...case语句中break关键字的用法,是Swift入门学习中的基础知识,需要的朋友可以参考下


