Re: Comparing string input to enum data type
- From: "dtschoepe@xxxxxxxxx" <dtschoepe@xxxxxxxxx>
- Date: 28 Feb 2007 10:17:40 -0800
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
.
- Follow-Ups:
- Re: Comparing string input to enum data type
- From: Walter Roberson
- Re: Comparing string input to enum data type
- References:
- Comparing string input to enum data type
- From: dtschoepe@xxxxxxxxx
- Re: Comparing string input to enum data type
- From: Bill Pursell
- Re: Comparing string input to enum data type
- From: Yevgen Muntyan
- Re: Comparing string input to enum data type
- From: CBFalconer
- Re: Comparing string input to enum data type
- From: Yevgen Muntyan
- Re: Comparing string input to enum data type
- From: Nelu
- Re: Comparing string input to enum data type
- From: Yevgen Muntyan
- Re: Comparing string input to enum data type
- From: CBFalconer
- Comparing string input to enum data type
- Prev by Date: Re: INT_MIN and compiler diagnostic
- Next by Date: Re: Comparing string input to enum data type
- Previous by thread: Re: Comparing string input to enum data type
- Next by thread: Re: Comparing string input to enum data type
- Index(es):
Relevant Pages
|