我是C新手,我發現枚舉非常好。我的程序獲取一個字符串,並使用枚舉做案例,然後(有時)我需要發回一個字符串匹配枚舉表中的一個。有沒有辦法用枚舉來做,或者我應該使用查找表? Something like this有沒有辦法返回到typedef枚舉的字符串?
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你能否詳細說明你的答案? – Juan 2013-03-13 10:24:57
同樣考慮到它與上一個問題非常相似(如果不相同),我應該刪除它嗎? – Juan 2013-03-13 10:33:16