嗨,如果您有这种情况,这是一种简单快捷的方法:
[快速模式]
int concated;
char ABC[4]="";int a=1,b=4,c=2; //char[] Initializing
ABC<-sprintf(ABC,"%d%d%d",a,b,c); //without space between %d%d%d
printf("%s",ABC); //value as char[] is =142
concated=atoi(ABC); //result is 142 as int, not 1,4,2 (separeted)
//now use switch case on 142 as an integer and all possible cases
[解释模式]
例如:我有很多菜单,第一个菜单上的每个选项都会将你带到第二个菜单,第二个菜单和第三个菜单也是如此。但是选项不同,所以你知道用户已经选择了 finnaly。例子:
菜单 1:1 ==> 菜单 2:4==> 菜单 3:2 (...) 选择是 142。其他情况:111,141,131,122...
解决方案:将第一个存储在 a,第二个存储在 b,第三个存储在 c。a=1, b=4, c=2
char ABC[4]="";
ABC<-sprintf(ABC,"%d%d%d",a,b,c); //without space between %d%d%d
printf("%s",ABC); //value as char[]=142
//now you want to recover your value(142) from char[] to int as int value 142
concated=atoi(ABC); //result is 142 as int, not 1,4,2 (separeted)