Skip to main content

Posts

Showing posts from 2015

printing enum as string

While coding C programming, there will be scenarios where you want to print the enum values as string while debugging. There are methods where you can define separate function which will return the string of definition, but the issue with that is , when you edit code, if we add a new enum value and forgot to add in the string conversion function/array, it will be give lot of problems and spend time on debugging After googling, i found on solution which has only one definition, I edited it to suit my requirements. Please check the code below #include<stdio.h> #define FOREACH_WEEKDAYS(WEEKDAYS) \             WEEKDAYS(SUNDAY)   \             WEEKDAYS(MONDAY)  \             WEEKDAYS(TUESDAY)   \             WEEKDAYS(WEDNESDAY)  \             WEEKDAYS(THURSDAY)  \         ...