Map enum to char and output with for loop
#include <stdio.h>
enum spectrum { red, orange, yellow} colour;
char *rainbow[] = { "red", "orange", "yellow" };
int main() {
for ( colour = red; colour <= yellow; colour++ ) {
printf ( "%s ", rainbow[colour]);
}
printf ( "\n" );
}
Related examples in the same category