Censoring a document

Pages: 12
Im writing a program that takes a datafile Badwords.txt which contains the words to be censored out from a txt file.

it will ask the user where the file is that is to be censored and then where to put the censored version of the file.

The output of the file should be exactly like the input file except the censored words are to be replaced with asterisks.The number of asterisks should match the number of letters in the word.

Spaceing, punctuation, and special symbols all remain unchanged.

My code looks like this so far. The way ive set it up is primitive, but i cannot understand some of the logic involved in accomplishing this goal.Im mainly concerned with how to go about doing this perhaps less specific to syntax(which im still working on)

#include <cstdlib>
#include <iostream>
#include <cctype>
#include <cstring>
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
ifstream inFile;
char fName[50];
char word='\0';
char words[1500][50];
int i,j,length;
char badword[20][20];
cout<< "Where is the location of the bad word list";
cin.getline(fName, 50);
inFile.open(fName);

while(!inFile.eof()) //To replace the words if they are to be censored
{
inFile.get(word);
for(j=0;j<1500;j++)
{
for(i=0; i<1500; i++)
{
if (word==badword[i])
{
length=strlen(word);
words[j]=word;
if (length==1);
words[j]=*;

if (length==2)
words[j]=**;

if (length==3)
words[j]=***;

if (length==4)
words[j]=****;

if (length==5)
words[j]=*****;

if (length==6)
words[j]=******;

if (length==7)
words[j]=*******;

if (length==8)
words[j]=********;

if (length==9)
words[j]=*********;

if (length==10)
words[j]=**********;


}
}
}
// in.get(nextCh)


}
return 0;
}





on another note I cannot find a good resource on how inFile.get(word); exactly works. does it read in one word at a time, and if so how does it know exactly what a word is with special charactors all over the place

Any help would be greatly appreaciated
Rather than using char arrays it would be much easier to use std::string:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>
#include <fstream>

// ...

std::ifstream ifs(fname); // input file stream

std::string word;

while(ifs >> word) // read each word from file stream
{
	// read was a success... check if word is bad
	
}

Or you may find it easier to read a whole line at a time:
1
2
3
4
5
6
7
std::string line;

while(std::getline(ifs, line)) // read each line from file stream
{
	// read was a success... search line for bad words
	
}

Last edited on
Interesting idea, as you can see me skills are very primitive as I have been doing some reading im regaining my skills, but the std::string you refer to i have never used much less heard of, i will be looking into this tonight and get back the the forums shorty after

much appreciated
The reference section here should be useful:
http://cplusplus.com/reference/string/string/

And for finding your bad words you could perhaps use this:
http://cplusplus.com/reference/string/string/find/
Ok after re thinking how to write this program logically ive come up with this basic start.

#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
ifstream inFile;
ofstream oFile;
int length;
string words;

inFile.open("namess.txt");

while(!inFile.eof()) // to get the words
{
getline(inFile,words);

cout<<words;
}



int pause; // to stop program
cin>>pause;

}







so it reads in and displays my document, but not at all correctly. the words are right but when it comes down to quote marks, commas, ect... it displays a funky charactor. but at any rate im closer then before

so now i need to search the strings for the words i want censored and then replace the charactors with '*' which in this new format ive yet to understand
Close... Don't loop on eof(). Instead use the following construct:

1
2
3
4
5
6
string line;  // an entire line of text (containing zero or more words)

while (getline(inFile,line))
{
  ...
}

Pleae use [code] tags.


Remember, you'll want to open two files: one for the bad words and one for the document to modify. You don't need to open them at the same time. (In fact, I recommend you first read in your list of bad words and then work on the document.)

For each line of text, you will want to find and replace every bad word with its .length() in asterisks. (This implies yet another loop inside your 'read/modify/print every line' loop. Here's a trick: a string of asterisks can be created by string(5,'*') -- just replace the 5 with the number of asterisks you want.

Use the string functions to .find() and .replace() text in the line. Don't forget to read up on the links Galik gave you.

Good luck!
Great call on the string functions duoas.

I should be able to get it from there, that is my program to do what it needs to, but my program reads in my txt file and it doesnt look the same, as there are odd charactors beign displayed in place of commas and quotations. example.Here is my txt file before i read it in.



So she set the little creature down, and felt quite relieved to see it trot away quietly into the
wood. “If it had grown up,” she said to herself, “it would have made a dreadfully ugly child: but it
makes rather a handsome pig, I think.” And she began thinking over other children she knew, who might
do very well as pigs, and was just saying to herself, “if one only knew the right way to change
them--” when she was a little startled by seeing the Cheshire Cat sitting on a bough of a tree a few
yards off.



and here is what it looks like when i cout it to the screen.

So she set the little creature down, and felt quite relieved to see it trot away
quietly into the wood. ôIf it had grown up,ö she said to herself, ôit would hav
e made a dreadfully ugly child: but it makes rather a handsome pig, I think.ö An
d she began thinking over other children she knew, who mightdo very well as pigs
, and was just saying to herself, ôif one only knew the right way to change them
--ö when she was a little startled by seeing the Cheshire Cat sitting on a bough
of a tree a few yards off.The Cat only grinned when it saw Alice. It looked goo

i see the need to format somehow but that still doesnt explain the odd charactors that appear
any ideas?

It's possible your console (this is a console program?) is using a code page that doesn't support 'smart' quotes, i.e. the ones the curve to signify the beginning or end of a quote. You may want to open the file in a text editor and change them to ASCII quotes.
A thoughtful insight and ideas I will use on my website. Youve obviously spent some time on this. Congratulations!
You will probably want to order your censored words by length before starting, with longer words first.

Because, if you have "ban" and "banana" in the list for example, if you find "ban" in the censored list first but the word was "banana", only the start of banana could be censored and you could have ***ana in the output

EDIT : that would be if you handle rawx texte, but if your code already separates words, you don't need it
Last edited on
Hmm ok, using the getline first to read in the badWords //(words to be censored) should i store them in a variable of an array to then perhaps do a forloop to .find and .replace each bad word.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
using std::string;

int main()
{
  ifstream inFile;
  ofstream oFile;
  int length;
  string words,badWords;
  int x,z,i;
  void wordswap(string &);  //function prototype
  
  inFile.open("namess.txt"); //file with the many sentances that need to be censored.
  
 while(!inFile.eof()) // to get the words
 {
   getline(inFile,words); // to read in the first line that will then be searched for badwords
   wordswap(words);     // function call
    //cout<<words;     
 }

  
    int pause; // to stop program.
    cin>>pause;
    
}
void wordswap(string &word) //Heart of program, Hopefully to find and replace the words with asterisks
{                           // problem ive encounterd here is that this needs to run through all the bad words
                            //for each use of getline(inFile,words)
      
while(!inFile.eof())
{
  inFile.open("words.txt");     //Not sure if my instances of opening two files are legal.
  getline(inFile,badWords);     //read in the badwords
   
       x=word.find(badWords);           //search for the badword in the txt file
       z=words.length(badWords);        // what is the length of the word to be replaced, to then be changed to asterisks.
       words.replace(I DONT KNOW WHAT TO PUT HERE)  // confused on the syntax here
  
  
}
  inFile.close();  // to close my badwords file
}








Here is where i am at now. Brains going to implode
I think your getting this, but you seem a bit confused about where to declare your variables. Each function holds its own variables that can not be accessed from other functions. So you can't declare everything in main() function and expect to use them in other functions like wordswap().

I have made some fixes and added some notes to your code so far for you to think about:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
using std::string;

int main()
{
	ifstream inFile;
	ofstream oFile;
	int length;
	string words/*, badWords*/; // badWords here can not be accessed from wordswap() function
	int x, z, i;
	void wordswap(string &);  //function prototype

	inFile.open("namess.txt"); //file with the many sentances that need to be censored.

	// while(!inFile.eof()) // Don't loop on eof()!!!
	while(getline(inFile, words)) // Loop only if getline() succeeded!
	{
		wordswap(words);     // function call
		//cout<<words;
	}

	int pause; // to stop program.
	cin >> pause;

	return 0;
}
void wordswap(string &word) //Heart of program, Hopefully to find and replace the words with asterisks
{ // problem ive encounterd here is that this needs to run through all the bad words
//for each use of getline(inFile,words)

	string badWords; // define it here where you use it, not in main()

	// You can't access the variable in main() in this function. You need to
	// declare another inFile object to read the bad words file:
	ifstream inFile;
	inFile.open("words.txt"); // open it BEFORE you start using it!

	// while(!inFile.eof()) // Don't loop with eof() !!
	while(getline(inFile, badWords)) // Loop if the read was successful!
	{
		// inFile.open("words.txt"); // Don't open it after you started using it!

		x = word.find(badWords);        //search for the badword in the txt file
		z = words.length(badWords); // what is the length of the word to be replaced, to then be changed to asterisks.
		words.replace(I DONT KNOW WHAT TO PUT HERE)  // confused on the syntax here


	}
	inFile.close();  // to close my badwords file
}

I didn't do the bit you asked for yet. Have a look at the docs for string::find() and string::replace():

std::string::find()
http://cplusplus.com/reference/string/string/find/

std::string::replace()
http://cplusplus.com/reference/string/string/replace/

I made the changes you reccomended, and added a few things myself epecially in the void wordswap definition.I am still getting errors which is fine that may just take a little more reading(i hope) but i still have a few logic issues that i had added as notes throught the program once again



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <string>
#include <iomanip>

//Object: read in a datafile named badWords.txt that contains words that cannot appear in another file.
//The output file should be the exact same as the input file except whenever a word from 
//badwords.txt is encountered in the input it should be replace with asterisks, the asterisks
//        should match the number of letters in the censored word.

using namespace std;
using std::string;

int main()
{
  ifstream inFile;
  ofstream oFile;
  int length;
  string words;
  int i;
  void wordswap(string &);  //function prototype
  
  inFile.open("namess.txt"); //file with the many sentances that need to be censored.
  
 while(getline(inFile,words)) //Main loop 
   { 
    wordswap(words);     // function call
   }
    int pause; // to stop program.
    cin>>pause;
    
    return 0;
}
void wordswap(string &words) //Heart of program, Hopefully to find and replace the words with asterisks
{                           // problem ive encounterd here is that this needs to run through all the bad words
                            //for each use of getline(inFile,words)
   int x,;
   string badWords; 
   string tempString                       
   string tempLength; // temp// to determine # of *to replace chars with                 
   ifstream inFile // do i need this declaration twice?
   inFile.open("words.txt");     ///ERROR
 
   
   while(getline(inFile, badWords))
{
       x=words.find(badWords);           //search for the badword in the txt file
       tempLength=words.length(badWords);        // what is the length of the word to be replaced, to then be changed to asterisks.
       for(int f=0;f>=tempLength;f++) // loop to add asterisks depending on how many charactors are in string
        tempString.insert('*');
       
       words.replace(x,tempLength,tempString);  // To replace the badword in words.txt at position x, with temp variable tempString
       tempString.clear();                     // Clears the temp string for use in the next getline function
  
}
  inFile.close();  // to close my badwords file
}

// On a last note-- lets say theres a sentance in my words.txt that reads "school is great" with the quotation marks
// Then in the badwords file there is a badword school without quotation marks
// will word.find(badwords) return the position of the word inludeing the paranthesis and then asterisk them all out or
// will it not censor any of it, or just part of it






Heres my error log:

Assignment 1/Project1.2.cpp: In function `void wordswap(std::string&)':
Assignment 1/Project1.2.cpp:42: error: `tempString' does not name a type
Assignment 1/Project1.2.cpp:44: error: `inFile' does not name a type
Assignment 1/Project1.2.cpp:47: error: `inFile' undeclared (first use this function)
Assignment 1/Project1.2.cpp:47: error: (Each undeclared identifier is reported only once for each function it appears in.)

Assignment 1/Project1.2.cpp:50: error: `tempLength' undeclared (first use this function)
Assignment 1/Project1.2.cpp:50: error: no matching function for call to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::length(std::string&)'
C:/Dev-Cpp/include/c++/3.4.2/bits/basic_string.h:537: note: candidates are: typename _Alloc::size_type std::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
Assignment 1/Project1.2.cpp:52: error: `tempString' undeclared (first use this function)

make.exe: *** ["Assignment 1/Project1.2.o"] Error 1

Execution terminated
I am going to chime in here:

Are you searching a given text file with a list of bad words or a single word along with the file you need to search for the given words?

in either case:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cctype>

// globals
std::vector<std::string> badwordlist;

void SetupBadWords()
{
       // I am either loading from a file or setting them by hand
       std::string IncomingWord;

       //loading by hand
       badwordlist.push_back("One");
       badwordlist.push_back("two");
       badwordlist.push_back("three");

      //loading by file, may need refinement for your needs.
      std::fstream badwordsfile;
      if( ! badwordsfile.open("badwords", std::ios::append) )
      {
             while(!badwordsfile.eof())
             {
                    badwordsfile >> IncomingWord;
                    badwordlist.pust_back(IncomingWord);
             }
     }
     else
     {
          // we had a problem opening the file exit code.
          // report the error and exit...
     }
}

// the two approaches to your problem

void AproachOne()
{
       // this is the easier of the two approaches.
       // open the file to scan...
       std::fstream ScanFile;
       std::osteam outFile; // will need to set up the open of it after we have the 
       std::string CurrentLine;
       std::vector<std::string>::iterator pListPos;
       std::string SearchWord;
       std::string::iterator pCurPos; // current position in the line
       std::string replace;

       if( !ScanFile.open("ScanFile.txt", std::ios::append) )
       {
              while(!ScanFile.eof())
              {
                      getline(ScanFile, CurrentLine);
                      if(!CurrentLine.empty())
                      {
                              for(pListPos = badwordlist.begin(); pListPos == badwordlist.end(); pListPos++)
                              {
                                      pCurPos = CurrentLine.find(badwordlist[pListPos]);
                                      while(pCurPos != std::string::npos)
                                      {
                                            // set up the replacement piece
                                            replace.assign("*", badwordlist[pListPos].length() );
                                            // replace in the line
                                            Currentline.replace(pCurPos, replace.length(), replace);
                                            // find the next position of the current bad word starting at the last known point
                                            pCurPos = CurrentLine.find(badwordlist[pListPos], pCurPos); 
                                      } // while pCurPos
                             } // for loop of badwordlist

                             // here is where I would send the converted line to the output file if it was opened.
                   } // check for line being empty.
          } // the while of eof (end of file)
     }
     else
     {
              // I had a problem opening the original file to scan.
     }
} // end of function.

void ApproachTwo()
{
       std::fstream ScanFile;
       std::osteam outFile; // will need to set up the open of it after we have the 
       std::string CurrentLine;
       std::vector<std::string>::iterator pListPos;
       std::string SearchWord;
       std::string::iterator pCurPos; // current position in the line
       std::string::iterator pSavePos; // this will be the remember point of a word.
       std::string replace;
       std::string extract;
       // the basic algorithm looks similar to the first
       
       if( !ScanFile.open("ScanFile.txt", std::ios::append) )
       {
              while(!ScanFile.eof())
              {
                      getline(ScanFile, CurrentLine);
                      if(!CurrentLine.empty())
                      {
                             pCurPos = CurrentLine.begin();
                             pSavePos = pCurPos;
                             while(pCurPos != CurrentLine.end())
                             {
                                    if(isalpha(*pCurPos))
                                    {
                                         extract+=*pCurPos;
                                    }
                                    else
                                    {
                                           if(!extract.empty())
                                           {
                                                   // take the extracted word and search the bad word list.
                                                   // if we find it in the list we set up replace
                                                   // pSavePos is the start position of the current word we are on.
                                                   // do the replacement similar to the first approach.
                                                   // clear extracted for the next word.
                                                   
                                                  // at the end set up the saveposition..
                                                  pSavePos = pCurPos;
                                           }
                                           else
                                           {
                                                    // this should put it on the non-alphabetic character.
                                                    pSavePos = pCurPos;
                                                    // can increment the position or can work from there. 
                                                   // just need to test for end of string...
                                                    
                                           }
                                  } // else on isalpha in <cctype>
                                  //increment the curPos...
                                  pCurPos++; 
                           } // the loop on CurrentLine

                           // write out the currentLine to the output file.
                    }// current line empty..
              } // eof while.
         } // good open of file.
         else
         {
                    // report the problem....
         }
} // end of function.
   


I apologize for pseudo code there I would have to think through the logic a little more in depth than I want to. I would like to see you work on the logic yourself.

I hope I gave you food for thought here.
Last edited on
where can i find references to learn these commands, i would have looked them up but do not know what they are called

std::fstream ScanFile;
std::osteam outFile; // will need to set up the open of it after we have the
std::string CurrentLine;
std::vector::iterator pListPos;
std::string SearchWord;
std::string::iterator pCurPos; // current position in the line
std::string replace;


mainly the std:: portion og the syntax, i dont know what it is doing and havent implemented any in my program got that reason.

I would love to look into your code more but when i dont know what these codes are doing i dont understand most of the program :D

Im under the impression my code is very close to the main goal, i have errors preventing me from running the program to see if i have any problems associated with functionality.

and btw, i am searching a given text file with a list of bad words, when ive found the badwords in the filer i replace them with '*'
std is part of the standard library of c++, if you need more info look in the Reference Section of this web site.

http://www.cplusplus.com/reference/

#include <cctype> and stuff are listed there.

Everything in my code can be found there.

Your given a scan file is what I assume, But my Code assumes you have a list of bad words you need to compare to or find in the original scan file.
Eureaka i may have just about defeated the code.
The program runs without any errors
but that doesnt mean it functions correctly

I suspect its near the end , keep reading at bottom

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73


#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

//Object: read in a datafile named badWords.txt that contains words that cannot appear in another file.
//        The output file should be the exact same as the input file except whenever a word from 
//        badwords.txt is encountered in the input it should be replace with asterisks, the asterisks
//        should match the number of letters in the censored word.

using namespace std;
using std::string;

int main()
{
  ifstream inFile;
  ofstream outputFile;
  int length;
  string words;
  int i;
  void wordswap(string &);  //function prototype
  
  inFile.open("namess.txt"); //file with the many sentances that need to be censored.
  outputFile.open("output.txt");
  
 while(getline(inFile,words)) //Main loop 
   { 
    wordswap(words);     // function call
    outputFile<<words;
   }
    int pause; // to stop program and see whats happening.
    cin>>pause;
    
    return 0;
}
void wordswap(string &words) //Heart of program, Hopefully to find and replace the words with asterisks
{                           // problem ive encounterd here is that this needs to run through all the bad words
                            //for each use of getline(inFile,words)
   int x;
   string badWords; 
   string tempString;                       
   int tempLength;               //Declarations 
   ifstream inFile; 
   inFile.open("words.txt");     
 
   
   while(getline(inFile, badWords))
{
       words.find(badWords,x);
       //x=words.find(badWords);                   //search for the badword in the txt file
       tempLength=badWords.length();
       //tempLength=words.length(badWords);        // what is the length of the word to be replaced, to then be changed to asterisks.
       for(int f=0;f>=tempLength;f++)            // loop to add asterisks depending on how many charactors are in string
       tempString.insert(0,tempLength,'*');
       
       words.replace(x,tempLength,tempString);  // To replace the badword in words.txt at position x, with temp variable tempString
       tempString.clear(); 
                           // Clears the temp string for use in the next getline function
  
}
  inFile.close();  // to close my badwords file
}

// On a last note-- lets say theres a sentance in my words.txt that reads "school is great" with the quotation marks
// Then in the badwords file there is a badword school without quotation marks
// will word.find(badwords) return the position of the word inludeing the paranthesis and then asterisk them all out or
// will it not censor any of it, or just part of it







Line 53 most exampled do me a horrible job of explaining the .replace function am i using it correctly here?
Okay you are getting close now. Replace works just the way you are using it. Again I made some fixes and some notes. This nearly works, however it only replaces ONE bad word per line! You are going to need to put in a loop when you search for the bad word in your input line to replace all of them. If there are no bad words left in the string then words.find() will return string::npos.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

//Object: read in a datafile named badWords.txt that contains words that cannot appear in another file.
//        The output file should be the exact same as the input file except whenever a word from
//        badwords.txt is encountered in the input it should be replace with asterisks, the asterisks
//        should match the number of letters in the censored word.

using namespace std;
using std::string;

int main()
{
	ifstream inFile;
	ofstream outputFile;
	int length;
	string words;
	int i;
	void wordswap(string &);  //function prototype

	inFile.open("input.txt"); //file with the many sentances that need to be censored.
	outputFile.open("output.txt");

	while(getline(inFile, words)) //Main loop
	{
		wordswap(words);     // function call

		// getline() deletes the end of line characters, so you need to add them to
		// the output
		outputFile << words << '\n';
	}
	int pause; // to stop program and see whats happening.
	cin >> pause;

	return 0;
}
void wordswap(string &words) //Heart of program, Hopefully to find and replace the words with asterisks
{ // problem ive encounterd here is that this needs to run through all the bad words
//for each use of getline(inFile,words)
	int x;
	string badWords;
	string tempString;
	int tempLength;               //Declarations
	ifstream inFile;
	inFile.open("words.txt");

	while(getline(inFile, badWords))
	{
		//words.find(badWords,x); // you need to set x to this value like you did before
		x = words.find(badWords);       //search for the badword in the txt file

		// DID WE FIND THE BAD WORD?
		if(x != string::npos) // string::npos means word was NOT found
		{
			tempLength = badWords.length();
			//tempLength=words.length(badWords);        // what is the length of the word to be replaced, to then be changed to asterisks.

			//for(int f = 0; f >= tempLength; f++) // f starts at 0 and is never going to be GREATER than tempLength!!!
			for(int f = 0; f < tempLength; f++) // loop while f is LESS THAN tempLength!
				//       tempString.insert(0,tempLength,'*'); // this is not what you want
				tempString.assign(tempLength, '*'); // use this

			words.replace(x, tempLength, tempString); // To replace the badword in words.txt at position x, with temp variable tempString
			// tempString.clear(); // no need to clear because we us assign() which does this for us
		}
	}
	inFile.close();  // to close my badwords file
}

// On a last note-- lets say theres a sentance in my words.txt that reads "school is great" with the quotation marks
// Then in the badwords file there is a badword school without quotation marks
// will word.find(badwords) return the position of the word inludeing the paranthesis and then asterisk them all out or
// will it not censor any of it, or just part of it
Very nice on finding that for loop error. i also am not sure why insert wouldnt work, unless your implementing that to save my .clear from needing to be used only.

My output is only asterisks now on several lines, im not sure why but i will be looking into it for a bit here.

Edit: Maybe its in my words.replace , but its only a hunch, syntax seems right.

Edit: Another thought, would i need a *ptr somewhere to reference back to string & of the function
Last edited on
Pages: 12