View Single Post
Join Date: Nov 2008
Posts: 13
Reputation: matt_570 is an unknown quantity at this point 
Solved Threads: 0
matt_570 matt_570 is offline Offline
Newbie Poster

Re: Determining the number of unique words in a .txt file

 
0
  #8
Dec 3rd, 2008
Ok I figured out I need to use "inFile.getline(line,length)" instead of "getline(inFile, line)". I created a struct like stated early. However I'm having trouble storing the words from the text file.

I use this function-

  1. void displayFile (char fileName[], words array[] )
  2. {
  3. int i = 0;
  4. ifstream inFile;
  5.  
  6. char line [101];
  7.  
  8. inFile.open(fileName);
  9.  
  10. while (inFile.getline(line,101))
  11. {
  12. cout << line << endl;
  13. array[i].word = line;
  14. i++;
  15. }
  16. inFile.close();
  17.  
  18. }
Where array, is an array of structs made up of character array"word" and an integer "count". Any help on storing the words and the number of words in the array would be helpfull.
Reply With Quote