enum Season {
Summer, Fall, Winter, Spring, SeasonCount
};
const char *seasonNames[] = {"Summer", "Fall", "Winter", "Spring"};
//C has no lookup by name: search the array of names,
//the index of the name is the value of the member;
//SeasonCount means "not found"
const char *strValue = "Summer";
enum Season summer = SeasonCount;
for (int i = 0; i < SeasonCount; i++) {
if (strcmp(seasonNames[i], strValue) == 0) {
summer = i;
break;
}
}
bool found = summer != SeasonCount;
//found is true
//summer is 0
printf("found is %s\n", found ? "true" : "false");
printf("summer is %d\n", summer);