Jerry Eckert writes:

> Is there a more elegant way to do the equivalent of a switch statement for a
> character string value than a chain of if (strcmp())... else if
> (strcmp())... else if.... ?

Not really.  You say "elegant", and to me that rules out most
nontrivial hacks that allow you to use a switch statement with a
string.

In C++ you might be able to make things a little bit
prettier, but you still can't really use a switch statement.

> What I tried to do was
> 
>     switch (char-var) {
>         case "string1":
>         ...
>     }

Loosely speaking, the cases in switch statments need to be integral
constants.  A character string in C doesn't really work here.

My advice to you:  just use strcmp().  It's straightforard to code and
when you look at the code 6 months from now it'll be very
understandable.

--kevin
-- 
Kevin D. Clark          |                          |
[EMAIL PROTECTED] | [EMAIL PROTECTED] |  Give me a decent UNIX
Enterasys Networks      | PGP Key Available        | and I can move the world
Durham, N.H. (USA)      |                          |


**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************

Reply via email to