Created
August 17, 2023 06:15
-
-
Save muaddib1971/e2e7969140871a02a743b50912b6e52e to your computer and use it in GitHub Desktop.
enums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
enum month { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; | |
const char* month_str[] = {"January", "February", "March", "April", | |
"May", "June", "July", "August", | |
"September", "October", "November", "December"}; | |
int main() { | |
enum month themonth; | |
for (themonth = JAN; themonth <= DEC; ++themonth) { | |
switch (themonth) { | |
case JAN: | |
printf("%s\n", month_str[JAN]); | |
break; | |
case FEB: | |
printf("%s\n", month_str[FEB]); | |
break; | |
case MAR: | |
printf("%s\n", month_str[MAR]); | |
break; | |
case APR: | |
printf("%s\n", month_str[APR]); | |
break; | |
case MAY: | |
printf("%s\n", month_str[MAY]); | |
break; | |
case JUN: | |
printf("%s\n", month_str[JUN]); | |
break; | |
case JUL: | |
printf("%s\n", month_str[JUL]); | |
break; | |
case AUG: | |
printf("%s\n", month_str[AUG]); | |
break; | |
case SEP: | |
printf("%s\n", month_str[SEP]); | |
break; | |
case OCT: | |
printf("%s\n", month_str[OCT]); | |
break; | |
case NOV: | |
printf("%s\n", month_str[NOV]); | |
break; | |
case DEC: | |
printf("%s\n", month_str[DEC]); | |
break; | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment