Name your program spam_check.c.2)Assume input is no longer than 1000 characters. Assume the input contains no more than 500 words. Assume each word is no more than 50 characters.3)You may find string library functions such as strtok, strcmp,andstrcpyhelpful.4)To read a line of text, use the read_linefunction in the lecture notes.

Respuesta :

Answer:

#include<stdio.h>

#include<string.h>

int main(){

  //creating array of strings of spam words

  char spam[23][15] = {"suspended","locked","bank","update","statement","personal","click","compromised","deactivated","reactivate",

  "account","alert","confirm","won","winner","seleced","claim","urgent","disabled","expire","investment","refinance","pre-approved"};

  //string to store input line

  char string[1000];

  //stores individual words in the line

  char words[500][50];

  //n - number of words given in the input line

  //count - number of spam words that are matching

  int n = 0, count = 0;

  //array of delimiters to split the words

  char delim[4][1] = {" ",",",".","!"};

  //reading the line

  printf("Enter a line :");

  //read a line from user

  scanf("%[^\n]%*c", string);

  //word stores a single word splitted using strtok and delimiter.

  char* word = strtok(string, delim);

  //loop runs till no more words exists

  while(word != NULL)

  {

      //copy the word to words[][]

      strcpy(words[n],word);

      word = strtok(NULL, delim);

      n++;

  }

  //checking if any word matches the spam words

  for(int i=0 ; i<n ; i++){

      for(int j = 0 ; j<23 ; j++){

          if(strcmp(words[i],spam[j]) == 0){

              //if match is found, increment the count value. If two strings are same then strcmp() returns 0, otherwise, it //returns a non-zero value.

              count++;

              break;

          }

      }

  }

  //printing the result

  printf("%d spam words found\n",count   );

  return 0;

}

ACCESS MORE