Reputation: 1
I am trying to compare and find matches in my two arrays but it is not working can any one help?
const char spam[30][30] = {"cash bonus","earn money","fast cash","free access","free gift","free membership",
"giveaway","million dollars","information you requested","act now","winner","you have been selected",
"congratulations","lose weight","meet singles","no cost","no interest","social securtiy number","bonus",
"ad","join millions","opt in","warranty","instant","prize","lowest price","get paid","get out of debt","one time","winning"};
char resp[SIZE][SIZE];//response string array
printf("Enter an email to be checked for spam\n");
scanf("%s", &resp);
//check if there is a match
for(int i = 0; i < 30; i++){
for(int j = 0; j < 30; j++){
resp[i][j] = tolower(resp[i][j]);//make it lowercase
int match = strncmp(resp[i], spam[i] );//compare
if(match == 0){
printf("This email is spam! :(\n");
}else{
printf("No match :) \n");
}//if else
}//for loop2
}//for loop1
Upvotes: -1
Views: 73
Reputation: 161
You can't really accomplish your goal in this way. Your spam library elements consist of 2 words separated by space. But your input is just a single word in each resp[i]
. (There is no simple way to take input in the 2D array aside from doing it word by word using scanf()
.
So when you compare a single word resp[i]
to a double word string cash bonus
, it will always return false
.
Here is a guide that can help you. Also, I would love to update the question. Is there any way to identify spam messages with a dictionary of strings, like the spam
2D array?
Upvotes: 0