title: opening and parsing a file in c++ to check for punctuation and to convert to lower case using two functions
body: <p>I am trying to open a file and parse a file with separate functions.</p>
  
  <p>when i parse the file, i want to read each line in my input file and i want to ignore any punctuation and make everything lowercase so that i can then print it out to a separate file into strings with no spaces or punctuation.</p>
  
  <p>i have tried to implement it but i cannot figure out what i am doing wrong. I am not getting an error but my output is not correct.</p>
  
  <p>this is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;ostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void processFile();
  void parseFile(ifstream&amp;, ofstream&amp;);
  
  int main()
  {
  
      //call function to open file and process
      cout &lt;&lt; "processing file" &lt;&lt; endl;
      processFile();
  
      return 0;
  }
  
  
  void processFile()
  {
      string newString;
      ifstream inFile;
      ofstream outFile;
  
      cout &lt;&lt; "opening files" &lt;&lt; endl;
      // open files
      inFile.open("inFile.txt");
      outFile.open("outFile.txt");
  
      cout &lt;&lt; "parsing file" &lt;&lt; endl;
      //parse file for capitalization &amp; punctuation
      parseFile(inFile, outFile);
  
      //close files
      outFile.close();
      inFile.close();
  }
  
  void parseFile(ifstream &amp;inFile, ofstream &amp;outFile)
  {
      //create and initialize variables
      string newString;;
      int i = 0;
  
      if(!inFile)
      {
          cout &lt;&lt; "ERROR!!! Cannot read file.";
      }
      else
      {
          do
          {
              //read each line in the input file until EOF
              getline(inFile, newString, '\n');
  
              //parse each string for punctuation
              while(newString[i])
              {
                  if(isalpha(newString[i])) //check each char in each      
                                            //string for punctuation
                  {
                      if(isupper(newString[i])) //check each string for 
                                                //capitalization
                      {
                          newString[i] = tolower(newString[i]); //convert 
                                                            //string to 
                                                            //lower case
                      }
                      outFile &lt;&lt; newString[i]; //output each line to file
                      cout &lt;&lt; newString[i];
                  }
                  i++;
                  if(newString[i] == '\n')
                      break;
              }
          } while(!inFile.eof());
      }
  }
  </code></pre>
  
  <p>this is my input:</p>
  
  <pre><code>racecar
  RACEcar
  rotator
  rotor
  civic
  Red rum, sir, is murder!
  Rats live on no evil star.
  Neil, a trap! Sid is part alien!
  Step on no pets.
  Dammit, I’m mad!
  </code></pre>
  
  <p>my expected output is everything in the input printed in lowercase, without punctuation and spaces</p>
  
  <p>this is my actual output:</p>
  
  <pre><code>racecarsirismurderraliena
  </code></pre>