Print text instead of value from C enum

前端 未结 12 988
借酒劲吻你
借酒劲吻你 2020-12-02 05:50
int main()
{

  enum Days{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};

  Days TheDay;

  int j = 0;

  printf(\"Please enter the day of the week (0 to         


        
12条回答
  •  情深已故
    2020-12-02 06:20

    I like this to have enum in the dayNames. To reduce typing, we can do the following:

    #define EP(x) [x] = #x  /* ENUM PRINT */
    
    const char* dayNames[] = { EP(Sunday), EP(Monday)};
    

提交回复
热议问题