Originally Posted by
Tommo
So the if/else statement above isn't very intuitive.
I'll say. (Are you sure you haven't confused yourself?) WordisinDictionary returns 1 if the word is NOT in the dictionary, and returns 0 if it is.
Code:
#include <stdio.h>
#include <string.h>
int WordisinDictionary( char *buffer, char *pattern )
{
if ( strstr( buffer, pattern ) == NULL )
{
return 1;
}
else
{
return 0;
}
}
int main( int argc, char *argv[] )
{
char *text[] =
{
"<A class=\"results\">No</A>", /* MATCH */
"<A class=\"results\">Yes</A>" /* NO MATCH*/
};
char pattern[25] = "class=\"results\">No";
size_t i;
for ( i = 0; i < sizeof text / sizeof *text; ++i )
{
int result = WordisinDictionary( text[i], pattern );
printf("%s is %s the dictionary\n", text[i], result ? "in" : "NOT in" );
}
return 0;
}
/* my output
<A class="results">No</A> is NOT in the dictionary
<A class="results">Yes</A> is in the dictionary
*/
I might just code it similar to this:
Code:
int result = strstr( text[i], pattern ) != 0;