相关疑难解决方法(0)

在C中使用枚举类型的变量作为字符串的简单方法?

这是我想要做的:

typedef enum { ONE, TWO, THREE } Numbers;
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写一个函数来执行类似于以下的切换案例:

char num_str[10];
int process_numbers_str(Numbers num) {
  switch(num) {
    case ONE:
    case TWO:
    case THREE:
    {
      strcpy(num_str, num); //some way to get the symbolic constant name in here?
    } break;
    default:
      return 0; //no match
  return 1;
}
Run Code Online (Sandbox Code Playgroud)

而不是在每种情况下定义,有没有办法使用枚举变量设置它,就像我在上面尝试做的那样?

c enums c-preprocessor

86
推荐指数
8
解决办法
9万
查看次数

真实使用X-Macros

我刚学会了X-Macros.您看过X-Macros的实际用途?他们什么时候成为工作的合适工具?

c macros c-preprocessor x-macros

67
推荐指数
5
解决办法
2万
查看次数

标签 统计

c ×2

c-preprocessor ×2

enums ×1

macros ×1

x-macros ×1