Jerry Eckert wrote:
> 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.... ?
I'll concur with many of the statements given here, and add a couple of
tips.
One technique that I use is to first save the result of strlen. Then you
only need to do a strcmp with strings of the same length. If you normally do
more that one or two string comparisons on the same string, then you could get
a nice speed-up from this technique.
If you really want to optimize things, do your own string comparision (in
combination with the technique above). Look at the string one character at a
time and keep track of only those strings that might still possibly match.
Unless your strings are very close, thing would be the quickest way to do it.
Consider using 'register' on variables that will change often and possibly
inlining your comparison function.
--
Bob Bell Compaq Computer Corporation
Software Engineer 110 Spit Brook Rd - ZKO3-3U/14
TruCluster Group Nashua, NH 03062-2698
[EMAIL PROTECTED] 603-884-0595
**********************************************************
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
**********************************************************