fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. #define SIZE 1000
  6. #define WORDS 10
  7.  
  8. int main(void)
  9. {
  10. char message[SIZE];
  11.  
  12. const char *spamWords[WORDS] =
  13. {
  14. "free",
  15. "winner",
  16. "win",
  17. "prize",
  18. "money",
  19. "urgent",
  20. "offer",
  21. "click",
  22. "buy",
  23. "congratulations"
  24. };
  25.  
  26. int score = 0;
  27.  
  28. printf("Enter an email message:\n");
  29. fgets(message, SIZE, stdin);
  30.  
  31. for (int i = 0; i < SIZE; ++i)
  32. {
  33. message[i] =
  34. (char)tolower((unsigned char)message[i]);
  35. }
  36.  
  37. for (int i = 0; i < WORDS; ++i)
  38. {
  39. if (strstr(message, spamWords[i]) != NULL)
  40. {
  41. ++score;
  42. }
  43. }
  44.  
  45. printf("Spam score = %d\n", score);
  46.  
  47. if (score >= 5)
  48. {
  49. printf("The message is probably spam.\n");
  50. }
  51. else if (score >= 2)
  52. {
  53. printf("The message may be spam.\n");
  54. }
  55. else
  56. {
  57. printf("The message is probably not spam.\n");
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5356KB
stdin
Standard input is empty
stdout
Enter an email message:
Spam score = 0
The message is probably not spam.