We run a clean ship here at St Joseph We do not abide by cur

We run a clean ship here at St. Joseph. We do not abide by cursing. However, lately I have noticed that more students have been using the distasteful word \"darn\" in their e-mails to me. This week, you are going to build a program that automatically censors this offensive word. Specifically, your program should:

Ask the user to enter a phrase. The user will indicate they are done providing input by hitting enter. You can assume that they will not enter a phrase longer than 1000 characters and that all the characters they do enter will be lower case.

If the word \"darn\" appears in their phrase, replace it with ****. You should only replace the word \"darn\". Words like \"cedarn\" and \"darner\" should not be modified.

If their phrase contained the word \"darn\", you should print out a warning message telling them to clean up their act. You should then display the censored phrase. If their phrase did not include darn, congratulate them on their manners and print out their message again.

Below are some example inputs and outputs. Your program should function identically:


With errors this time.


Challenge 1: Make \"darn\" variable, so that it is very easy to change it to another disgusting word that would then be censored. Hint: It will help if you make two new variables, one an array of characters and one that holds the length of the curse word.
Super Challenge: Make it so that the user can enter in a set of curse words that your program will censor. Hint: You\'ll need a 2D array

Solution

Program-

main() {

char msg[1000], ch;
  
int i = 0;
char array_of_string[100][20];
int string_num = 0;
int word_size = 0;
int msg_index = 0;
char curse[3]={\"darn\"};


while ((ch = getchar()) != \'\ \')
msg[i++] = ch;

   msg[i] = \'\\0\';


int flag=0;

while (msg[msg_index] != \'\\0\')
{
   if (msg[msg_index] != \' \')
   {
  
array_of_string[string_num][word_size] = msg[msg_index];
word_size++;

   }
   else {
  
array_of_string[string_num][word_size] = \'\\0\';
string_num++;
word_size = 0;
}
}


for(int i = 0; i < 100; i++)
{
if(array_of_strings[i] != \'\\0\')
   {
for(int j = 0; j < 3; j++)
   {

    if(strcmp(msg, array_of_strings[i]) == 0)
{
      
flag=1;
       char *p=array_of_string[i];
       while (*p != \'\\0\')
       {
        *p = \'*\';
        p++;
       }
printf(\"%s\\t\",array_of_string[i]);
}
else
       printf(\"%s\\t\",array_of_string[i]);
break;
}
}
}


if(flag==0)
{
   print (\"congrats u have entered an uncensored phrase\ \");

}
else
{

print (\"warning!!!ur phrase contains uncensored words!!clean up\ \");

}

}

We run a clean ship here at St. Joseph. We do not abide by cursing. However, lately I have noticed that more students have been using the distasteful word \
We run a clean ship here at St. Joseph. We do not abide by cursing. However, lately I have noticed that more students have been using the distasteful word \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site