Im trying to write a C program where the number of character
I\'m trying to write a C++ program where the number of characters in each word of a text file is counted. I\'m having trouble defining in my loop exactly when a word begins and ends (using characters). How can I reword this loop so that it recognizes a word and adds the number of characters in it to the variable called \"word?\" Here\'s what I have so far:
 #include <iostream>
 #include <fstream>
 #include <string>
 using namespace std;
 int main(){
 ifstream fin(\"file.txt\");
 int word=0;
 char ch;
 while(fin && ch!= \'.\'){
   if(ch==\' \' || ch==\'\ \')
    word++;
 //It is wrong because some of the text may have large portions of blank spaces which, by this loop, would be counted as chars in a word. Please explain all steps in logic.
Solution
//main.cpp
=========================================================
out.txt
| Time is a great teacher but unfortunately it kills all its pupils. | 

