strstr and occurrences to match

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-04-27T21:16:57Z Indexed on 2010/04/27 21:23 UTC
Read the original article Hit count: 153

Filed under:
|

I have several possible occurrences to test with strstr.

if ((a = strstr(string, "FOO")) != NULL || (a = strstr(string, "BAR")) != NULL ||
    (a = strstr(string, "FOO2")) != NULL ||(a = strstr(string, "BAR2")) != NULL ||
    (a = strstr(string, "FOO3")) != NULL ||(a = strstr(string, "BAR3")) != NULL) // do something

and then based on the occurrence found I need to do

 var = strlen("THE_ONE_MATCHED_ABOVE");

What would be a good way to do this without using lots of if statements?

© Stack Overflow or respective owner

Related posts about c

    Related posts about strstr