hi
m trying to write a code that would find an abusive word from a given a string and then compare this word with the list of abusive words, maintained in an array char abusive[20], and replace them with ####.
this is how m coding it.
firstly get the first word of the string and then compare this word with all the abusive words in abusive[], and if found then replace it by ####
void main()
{
int i=0;
clrscr();
char ch[20],*s,ch1[20];
cout<<"Enter ur sentence:\n";
gets(ch);
s=ch;
//while there is a character to be read ,move on
while(*s!='\0')
{
if(*s==' ') // if found a 'space' ,ie if found a ' word'
{
goto l1;
}
else //if not, ,just copy the content of the given string into another string
{
ch1[i]=*s;
i++;
s++;
}
}
l1:
puts(ch1); //print the word just found
//Problem 1:
here ,how to make the ch1[] empty again?(so that next time it again contains the word found after the space)
// now compare this word with the list
for(int i=0;i<20;i++)
{
if(abusive[i]==ch[??])// Prblem 2:ch[20] or just ch[]
{
//Problem 3: how to replace this abusive word just found by ####?
}
getch();
}
m trying to write a code that would find an abusive word from a given a string and then compare this word with the list of abusive words, maintained in an array char abusive[20], and replace them with ####.
this is how m coding it.
firstly get the first word of the string and then compare this word with all the abusive words in abusive[], and if found then replace it by ####
void main()
{
int i=0;
clrscr();
char ch[20],*s,ch1[20];
cout<<"Enter ur sentence:\n";
gets(ch);
s=ch;
//while there is a character to be read ,move on
while(*s!='\0')
{
if(*s==' ') // if found a 'space' ,ie if found a ' word'
{
goto l1;
}
else //if not, ,just copy the content of the given string into another string
{
ch1[i]=*s;
i++;
s++;
}
}
l1:
puts(ch1); //print the word just found
//Problem 1:
here ,how to make the ch1[] empty again?(so that next time it again contains the word found after the space)
// now compare this word with the list
for(int i=0;i<20;i++)
{
if(abusive[i]==ch[??])// Prblem 2:ch[20] or just ch[]
{
//Problem 3: how to replace this abusive word just found by ####?
}
getch();
}
Comment