c - strstr and occurrences to match -
i have several possible occurrences test 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) //
and based on occurrence found need
var = strlen("the_one_matched_above");
what way without using lots of if statements?
are willing use comma operator:
if ((lookfor = "foo", = strstr(string, lookfor)) != null || (lookfor = "bar", = strstr(string, lookfor)) != null || ...) { var = strlen(lookfor); }
the comma operator allow evaluate multiple expression in left right order. value of expression whole value of rightmost esub-expression.
Comments
Post a Comment