在C中使用字符串的switch语句 [英] switch statement using string in C

查看:34
本文介绍了在C中使用字符串的switch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
C/C++:非整数切换
C/C++ switch case with string

我将字符串传递给函数 get_band(char *str)然后我将传递的参数与特定字符串进行比较

I am passing a string to a function get_band(char *str) Then I am comparing the passed argument with a specific string

if(strcmp(str, "auto"))
{
  //do something
}

我的问题是 - 因为我有很多要比较的字符串,我如何使用 switch 语句而不是 if/else,因为 switch 语句只支持整数类型.

My question is - since i have many number of strings to compare, how can i use switch statement instead of if/else, since switch statement supports only integral type.

推荐答案

简答:你不能.

长答案:这个问题是 C/C++ switch case with string.

Long answer: this question is a duplicate of C/C++ switch case with string.

这篇关于在C中使用字符串的switch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆