title: Reads a file but prints integers that are not in the read file
body: <p>I am having trouble getting a file to read and then print a list to another file, line by line of the number of occurrences of each.  </p>
  
  <p>I works, however it prints the numbers: 1, 2, 3, 4, and 5 to the output file which are not in the read file</p>
  
  <p>The struct:</p>
  
  <pre><code>struct entry {
  string word;
  string word_uppercase;
  int number_occurences;
  </code></pre>
  
  <p>};<br>
      <code>//for array<br>
      entry myEntryArray[MAX_WORDS];<br>
      int addNewEntryHere=0; //next empty slot</code></p>
  
  <p>My main calls extractTokensFromLine to read and put in an array:</p>
  
  <pre><code>void extractTokensFromLine(std::string &amp;myString) {
      const char CHAR_TO_SEARCH_FOR = ' ';
      stringstream ss(myString);
      string tempToken;
      //Extracts characters from is and stores them into str until the delimitation character delim is found
      while (getline(ss, tempToken, CHAR_TO_SEARCH_FOR)) {
          processTokenArray(tempToken);
      }   
  }   
  </code></pre>
  
  <p>It goes through each line word by word to put in an array:</p>
  
  <pre><code> void processTokenArray(string &amp;token) {
      //temp uppercase for compare
      string strUpper = token;
      toUpper(strUpper);
      //see if its already there
      for (int i = 0; i &lt; addNewEntryHere; ++i) {
          if (strUpper == myEntryArray[i].word_uppercase) {
              //yep increment count
              myEntryArray[i].number_occurences++;
              return;
          }
      }
      //nope add it
      myEntryArray[addNewEntryHere].word = token;
      myEntryArray[addNewEntryHere].number_occurences = 1;
      myEntryArray[addNewEntryHere].word_uppercase = strUpper;
  
      //where next place to add is
      addNewEntryHere++;
  }
  </code></pre>
  
  <p>It then writes the Array to a file (each word and its number of occurrence):</p>
  
  <pre><code>bool writeArraytoFile(const std::string &amp;OUTPUTFILENAME) {
      fstream outfile;
      if (!openFile(outfile,OUTPUTFILENAME,ios_base::out))
          return false;
      int var;
      for (var = 0; var &lt; addNewEntryHere; ++var) {
          string word = myEntryArray[var].word;
          if(word != " " &amp;&amp; word != "")
              outfile&lt;&lt;myEntryArray[var].word &lt;&lt; " " &lt;&lt;IntToString(myEntryArray[var].number_occurences)&lt;&lt;std::endl;
      }
      closeFile(outfile);
      return true;
  }
  </code></pre>
  
  <p>The Read File is TestData.txt:</p>
  
  <p>I think I should like a bit of butter<br>
  And If its not<br>
  too much trouble some toast as well. And while you are in the kitchen a brace of expressos for me and my man here.  </p>
  
  <p>My Output file (sorted using the following method):</p>
  
  <pre><code>void sortVector(sortOrder so = NUMBER_OCCURRENCES) {
      bool shouldSwap = false;
      for (int var = 0; var &lt; addNewEntryHereV; ++var) {
      for (int var1 = var+1; var1 &lt; addNewEntryHereV; ++var1) {
          switch (so) {
              case ASCENDING:
                  shouldSwap =!compareAscendingV(myEntryVector, var, var1);
                  break;
                  //TODO handle the following cases appropriately
              case DESCENDING:
                  shouldSwap =!compareDescendingV(myEntryVector, var, var1);
                  break;
              case NUMBER_OCCURRENCES:
                  shouldSwap =!sortbyOccurrenceV(myEntryVector, var, var1);
                  break;
              default:
                  break;
              }
              if (shouldSwap){
                  std::string tmp = myEntryVector._V.at(var);
                  myEntryVector._V.at(var) = myEntryVector._V.at(var1);
                  myEntryVector._V.at(var1) = tmp;
              }
          }
      }
  }
  </code></pre>
  
  <p>Actual Output:  </p>
  
  <p>And 3<br>
  4 2<br>
  of 2<br>
  a 2<br>
  I 2<br>
  here. 1<br>
  man 1<br>
  my 1<br>
  me 1<br>
  for 1<br>
  expressos 1<br>
  brace 1<br>
  kitchen 1<br>
  the 1<br>
  in 1<br>
  are 1<br>
  you 1<br>
  while 1<br>
  well. 1<br>
  as 1<br>
  toast 1<br>
  some 1<br>
  trouble 1<br>
  much 1<br>
  too 1<br>
  5 1<br>
  3 1<br>
  2 1<br>
  1 1<br>
  not 1<br>
  its 1<br>
  If 1<br>
  butter 1<br>
  bit 1<br>
  like 1<br>
  should 1<br>
  think 1  </p>
  
  <p>Any sort of suggestion would be greatly appreciated, 
  thanks</p>