#include <stdio.h> #include <string.h> #include <stdbool.h>
bool isStopWord(char *word) { const char *stopWords[] = {"the", "and", "a", "an", "in", "on", "at", "to", "for", "of", "or", "with", "is", "are"}; int numStopWords = sizeof(stopWords) / sizeof(stopWords[0]); for (int i = 0; i < numStopWords; i++) { if (strcmp(word, stopWords[i]) == 0) { return true; } } return false; }
bool detectSpamMessage(char *text) { char *token = strtok(text, " ,.-"); const char *spamWords[] = {"win", "free", "claim", "prize"}; while (token != NULL) { for (int i = 0; i < sizeof(spamWords) / sizeof(spamWords[0]); i++) { if (strstr(token, spamWords[i]) != NULL) { return true; } } token = strtok(NULL, " ,.-"); } return false; }
bool detectFraudLink(char *text) { char *link = strtok(text, " ,"); const char *fraudDomains[] = {"fakebank.com", "phishingsite.org"}; while (link != NULL) { if (strstr(link, "http") != NULL || strstr(link, "https") != NULL) { for (int i = 0; i < sizeof(fraudDomains) / sizeof(fraudDomains[0]); i++) { if (strstr(link, fraudDomains[i]) != NULL) { return true; } } } link = strtok(NULL, " ,"); } return false; }
int main() { char emailText[] = "Congratulations! You've won a free vacation. Click here to claim your prize: https://notascam.com"; if (detectSpamMessage(emailText)) { printf("This is a spam message\n"); } if (detectFraudLink(emailText)) { printf("This contains a fraud link\n"); }
return 0;
}