Re: Comparing string input to enum data type



Here's what I ended up doing....

#define COLORS red, blue, green, yellow, black, purple, pink

..
..
..

enum color readColor(char * theFavColor)
{
enum colors { COLORS };
enum colors theColor;
if ( strcmp(color, "red") == 0 )
theColor = red;
else if ( strcmp(theFavColor, "blue") == 0)
theColor = blue;
else if ( strcmp(theFavColor, "green") == 0)
theColor = green;
else if ( strcmp(theFavColor, "yellow") == 0)
theColor = yellow;
else if ( strcmp(theFavColor, "black") == 0)
theColor = black;
else if ( strcmp(theFavColor, "purple") == 0)
theColor = purple;
else if ( strcmp(theFavColor, "pink") == 0)
theColor = pink;

return theColor;
}

This will work for now...

David

.



Relevant Pages