Question: Calculate the number of words in a paragraph entered algorithm : 1. store the paragraph entered into a .txt file 2. read the words from file, which separated by spaces 3. loop step 2 until no words left to read 4. display the number of loops repeated. How to excape the loop with condition there's no more words in the txt file ?
I could not get whats your query or do you want us to write the program for you? If that is the case this is a forum where people help each other and not a free home work help store.
This is my code Code: #include <iostream.h> #include <conio.h> #include <fstream.h> int main() { ofstream outputfile; ifstream inputfile; char X[500],a[50]; outputfile.open("abc.txt"); cout << "Type the paragraph and will count the words you typed"; cin.get(X,500); outputfile << X; outputfile.close(); inputfile.open("abc.txt"); for (int count=0 ; [COLOR="Red"][SIZE="4"][ ][/SIZE][/COLOR] ; count++) inputfile >> a; getch(); return 0; } The [ ] is the part i dunno how to write. hope somebody can help.
You can put inputfile >> a; because it will return null when the EOF is reached. Just check the doc to make it 100% sure