// This program outputs the number of words in an input text file.

#include <iostream.h>
#include <fstream.h>

int main()
{
        char currChar,prevChar; // variable declaration
        ifstream fin;
        int numWords = 0;

        fin.open("test.dat");   // Open the input file

        fin.get(currChar);
        prevChar = currChar;
        fin.get(currChar);   // extract characters from the file

        while (fin) {

            if ((prevChar != '\n') && (prevChar != ' ')) {
                if ((currChar == '\n') || (currChar == ' '))
                        numWords++;
                }

                prevChar = currChar;
                fin.get(currChar);
        }

        cout << "The file Contains " << numWords << " words\n";

        return(0);
}
