【发布时间】:2013-03-13 10:10:46
【问题描述】:
我是 C 新手,我发现枚举非常好。我的程序获取一个字符串,并使用枚举来处理案例,然后(有时)我需要发回一个与枚举表中的字符串匹配的字符串。有没有办法使用枚举或我应该使用查找表? Something like this
typedef enum {
string1,
string2,
string3,
string4,
BADKEY
} strings;
function(string1); //will send the integer,
//but would love to be able to send the string.
function(char *string) {
...
}
【问题讨论】:
-
感谢您的链接,那里有一些好主意。 @QuentinUK 你能详细说明你的答案吗?
-
另外考虑到它与上一个问题非常相似(如果不一样)我应该删除它吗?