The program is in C. } } i = i + 1; } i + i + 1; } return 0; } int main() { /**
ID: 3699187 • Letter: T
Question
The program is in C.
} }
i = i + 1; }
i + i + 1; }
return 0; }
int main() {
/** Variables and Function call to read in a phrase should be here**/
if(1 = foul) {
printf(" There was potty language in your phrase. It was censored. See below: "); }
else {
return 0; }
The program should ask the user to enter a phrase. If the word "darn" appears in their phrase it should replace with ****. If their phrase contained the word "darn" you should print out a warning message telling them to clean their act up. If their phrase did not include "darn" congrantualte them on their manners.
Explanation / Answer
#include <stdio.h>
int censor(char[], int, char[],int);
int main() {
int i=0;
/** Sets curse word **/
int csize= 5;
char curse[5]= "darn"; // the curse words
char str[20];
printf("Enter phrase: ");
scanf("%s", str);
printf("your phrase: ");
for(i=0; str[i]!='';i++)
printf("%c.", str[i]);
int strsize;
for(strsize= 0; str[i] != ''; ++strsize);
/** Variables and Function call to read in a phrase should be here**/
int foul= censor(str, strsize, curse, csize);
if(1== foul) {
printf(" There was potty language in your phrase. It was censored. See below: ");
}
else {
printf(" Your sentence was clean. Here is what you entered: ");
}
// printf("%s ", str);
return 0;
}
int censor(char phrase[], int psize, char curses[], int csize)
{
int n;
int i,foul,found=0;
i= 0;
while(phrase[i] != '')
{
/** If the first letter matches **/
if(phrase[i]== curses[0])
{
int j;
j= 0;
int match;
match= 1; // match is true
while(curses[j] != '' && match == 1)
{
if(curses[j] != phrase[i+j])
{
match= 1; // match is false
}
}
if(curses[j]== '')
{
if(phrase[i+j]== ' ' || phrase[i+j] == '')
{
foul= 1;
int k;
k= 0;
while(k <= j);
{
found=1;
phrase[i+k]= '*';
k= k + 1;
}
}
/** Skip to the next word **/
while(phrase[i] != ' ' && phrase[i] != '')
{
i= i + 1;
}
i + i + 1;
}
}
}
if(found==1) return 1;
else return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.