【发布时间】:2015-05-01 02:46:56
【问题描述】:
我正在尝试编写函数,当我在其参数中传递错误时将返回正确的字符串。但是我不清楚如何为字符串分配负索引(对应于枚举FILE_ERRORS_t),你能澄清一下吗?
typedef enum {
FOPEN_ERROR=-1,
FREAD_ERROR=-2,
FWRITE_ERROR=-3,
FSEEK_ERROR=-4,
FCLOSE_ERROR=-5
} FILE_ERRORS_t;
#define printErr (const char*[5]){"Cannot open file", "Cannot read file", "Cannot write file", "fseek fail", "fclose fail" }
【问题讨论】:
-
反转
enum。现在使用索引[ERROR+5]
标签: c string c-preprocessor