title: Strtok returning extra data at end of line
body: <p>I have been messing with this code for hours upon hours and am looking for some advice. I am using strtok to get words from a string, but I keep getting extra data at the end of each line. I have the following code:</p>
  
  <pre><code>cout &lt;&lt; "\n\n6. Load File:\n";
          getline(cin, inFile);
          inFile = path + inFile;
          myfile.open(inFile.c_str());
              while (myfile.is_open() == false)   //check to make sure file exists
              {
                  cout &lt;&lt; "\nPlease enter in a valid file name: ";
                  getline(cin,inFile);
                  inFile = path + inFile;
                  myfile.open(inFile.c_str());
              }
                  getline (myfile,line);
                  while ( myfile.good() )     //while the file is running, run below code
                  {
                      getline (myfile,line);
                      //cout &lt;&lt; line;
                      char str[line.length()];
                      char * pch;
                      for (int i=0;i&lt;line.size();i++) { //creates a char array from characters
                          str[i]=line[i];
                      }
                      pch = strtok(str," ,-!?\r\t\f\v\n\0|/\\_"); //eliminates whitespace,etc in char array
                      while (pch != NULL)
                      {
                          printf ("%s\n",pch);
                          pch = strtok (NULL, " ,-!?\r\t\f\v\n\0|/\\_");  //grabs next word
                      }
  
                  }
          myfile.close();
  </code></pre>
  
  <p>Now this code gives me my desired word output, but with random crazy values from memory at the end of each line. See below: <br><br>
  Load File:<br>
  cars1.txt<br>
  Jalopy<br>
  Blue<br>
  3402.99<b>\244\363P</b><br>
  Rustbucket<br>
  Brown<br>
  44.99<b>P</b><br>
  Lemon<br>
  Yellow<br>
  4226.99<b>99P</b><br></p>
  
  <p>Please help and many thanks!</p>