Print text instead of value from C enum

前端 未结 12 1019
借酒劲吻你
借酒劲吻你 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:22

    The way I usually do this is by storing the string representations in a separate array in the same order, then indexing the array with the enum value:

    const char *DayNames[] = { "Sunday", "Monday", "Tuesday", /* etc */ };
    printf("%s", DayNames[Sunday]); // prints "Sunday"
    

提交回复
热议问题