how to compare between enum elements in same struct?
Ok I am in error coding mode (for a bit) and I need to know how to get a comparison from a typedef enum.
Code:
typedef enum { Code:
switch (c) Code:
programName -C -c -g 300x200 filename.jpg I know how to get the element number but how to get the names to perhaps do a string compare, or whatever means to compare them after the (fact) switch because they are in the same struct. because this is always going to match. (prob because its always using the last set mode to look at both sides) .. yes? Code:
void check_options(void) |
You cannot get the name from the value in an enum directly.
When handling mutually exclusive options I typically organize things such that the first (or last) one given in input order wins and ignore others or throw up an error if necessary. If I am reading your post correctly, your code would only use the last value assigned to opts.mode if the opts struct is only actually used after the switch. Adapting your check_options(...) example test to set, and prevent resetting the mode, something like this might do it: Code:
void check_set_mode(int mode) Code:
switch (c) |
Quote:
I can put my mind to this better, there has to be a way to get the name itself out of it, I have a vague memory seeing something on that, getting the actual element name, then it is just then a matter of order - putting the set value perhaps in a temp and using that to keep the value of the first mode setting from being over written on another pass within the loop, if it loops around picks up the first -C store that value in a temp, second loop pass opts.mode gets changed to -c Code:
first pass or maybe dropping the second mode setting, then taking that first mode setting and using that to set the image, perhaps, doing or trying what you suggested or do a little bit of rewriting - rethinking and rewriting. time and testing will tell. Thanks for your suggestion. |
You are welcome!
If you are free to add a member to the opts struct, then one easy way to get both option names (characters) together might be... Add a character member to the opts struct... Code:
... Code:
void check_set_mode(int mode, char opt) Code:
switch (c) |
All times are GMT -5. The time now is 09:24 PM. |