Write a program system that reads several lines of information from a data file and prints each word of the file on a separate line of an output file followed by the number of letters in that word.
Also, print a count of words in the file on the screen when done. Assume that words are separated by one or more blanks.
Thus far I have only opened the in and out file that we are reading and writing to. I know I have to use some type of getline function which reads each line and separates each individual word. After that I need to us a function with using getnextchar to count characters.
I think I can figure out the character counting part, but am having trouble with the getting each word from the lines. I know it is like: get char until next chat =s ' ' and this equals a word. Keep doing this until you hit NWLN or eds.eof.
this may be completely wrong^^ Can you steer me in the right directions?
thanks.
WIll that separate each word based on spaces though? So since I am using functions for this project, I just need to turn the above into a function and then it will work?
That will take each word (and by word in a text file, i mean each group of characters on their own, each word is separated by a space), and place it on a new line. If it doesnt work in one funciton, you might split it up into two functions, but for this one you dont need to.
If you want each word to be on the same line in a space, just remove: <<endl; and put: cout <<" "; . or you can format it however you want.
You could give the user the option to enter what to put in the first file, and then it writes to then other file.
so:
1 2 3 4 5 6
string input;
cout << "Write something to the file: ";
cin >> input;
outFile.open("output.txt");
outFile << input; //writes what the user entered to the file;