The easiest way is to write an elseif ladder.

#define strEQ(a,b) (strcmp(a,b)==0)
if ( strEQ(ss,"Test1") )
    blah1;
elseif ( strEQ(ss,"Test2") )
    blah2;
...
...
else
    nomatch();

The fastest way (execution-wise) is to write a finite state machine which
would touch each character of ss exactly twice. That goes way beyond the
scope of this mailing list, but you can write me privately on how to get
started.

BTW, back in 1979 I did my share of PL/I programming as well. Then I went
to work with a bunch of guys to write a PL/I compiler :-)

-- 
-Time flies like the wind. Fruit flies like a banana. [EMAIL PROTECTED]
-Stranger things have happened but none stranger than this. Steven W. Orr-
Does your driver's license say Organ Donor?Black holes are where God \
-------divided by zero. Listen to me! We are all individuals!---------

On Tue, 4 Apr 2000, Jerry Eckert wrote:

=>Hi Folks,
=>
=>I hope it's not inappropriate to ask a C language question here.
=>
=>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.... ?
=>
=>What I tried to do was
=>
=>    switch (char-var) {
=>        case "string1":
=>        ...
=>    }
=>
=>Eventually I figured out character strings aren't a data type in C.  Sigh...
=>
=>Thanks.
=>Jerry
=>(PL/I programmer struggling to learn C while writing code on a deadline
=>GAK!)


**********************************************************
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