最近在进行GPIO的测试中,想使用switch_case嵌套的方式进行GPIO的控制,但是进行传参的过程中,一直存在问题,至今仍未解决,应该是一些地址的输入有误,但是就此学习了一下switch_case嵌套,供大家参考!
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(int agrc,const char * argv[]) { unsigned int mux_id = atoi(argv[1]); printf("mux_id = %d n",mux_id); unsigned int mux_number = atoi(argv[2]); printf("mux_number = %d n",mux_number); switch (mux_id) { case 1000: switch (mux_number) { case 1: printf("1000_1n"); break; case 2: printf("1000_2n"); break; default: printf("1000_othersn"); } break; case 2000: switch (mux_number) { case 2: printf("2000_2n"); break; case 3: printf("2000_3n"); break; default: printf("2000_othersn"); } break; case 3000: switch (mux_number) { case 3: printf("3000_3n"); break; case 4: printf("3000_4n"); break; default: printf("3000_othersn"); } break; case 4000: switch (mux_number) { case 4: printf("4000_4n"); break; case 5: printf("4000_5n"); break; default: printf("4000_othersn"); } break; case 5000: switch (mux_number) { case 5: printf("5000_5n"); break; case 6: printf("5000_6n"); break; default: printf("5000_othersn"); } break; case 6000: switch (mux_number) { case 6: printf("6000_6n"); break; case 7: printf("6000_7n"); break; default: printf("6000_othersn"); } break; case 7000: switch (mux_number) { case 7: printf("7000_7n"); break; case 8: printf("7000_8n"); break; default: printf("7000_othersn"); } break; case 8000: switch (mux_number) { case 8: printf("8000_8n"); break; case 9: printf("8000_9n"); break; default: printf("8000_othersn"); } break; default: printf("others in the end!n"); } return 0; }
编译后进行传参,./main agrv[0] argv[1],得到如下结果:
这种结果与逻辑分析一致,得以验证switch_case嵌套!
最后
以上就是怕孤独板凳最近收集整理的关于switch_case嵌套使用举例的全部内容,更多相关switch_case嵌套使用举例内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复