I'm trying to write a spam checker using strstr, but I'm having trouble getting it to work properly. I want it to increment the counter when it finds a match, then if 2 or more matches are found to report spam. However it is incrementing when any word/phrase other then the compare string is entered. It also doesn't print the "no spam" message regardless of what is entered. Here is what I have got so far:
Code:
#include <stdio.h>
#include <string.h>
int main (void)
{
char input[128];
int counter;
counter = 0;
fgets (input, sizeof(input), stdin);
if (strstr(input, "free car") != NULL)
counter = counter +1;
else
if (strstr(input, "credit") != NULL)
counter = counter +1;
else
if (counter = 2)
printf( "message contains spam\n" );
else
printf( "no spam found\n" );
}