/*	File Statistics program.
	Counts number of characters and lines in one or more text files specified
	by the user. End-of-line characters are not counted as characters.             */

#include <iostream.h>
#include <fstream.h>
#include <lvpstring.h>
//#include <lvp\bool.h>

using namespace std;	// October 5, 2001

//--------------------------------------------------------------------------------
void DisplayStats(ifstream &InFile)
/*	Displays the number of characters and lines in InFile.
	End-of-line characters are not counted as characters.
	Pre: InFile open.
	Post: File statistics displayed.                                        */
{
	lvpstring S;
	long TotalChars = 0;
	long TotalLines = 0;
	while (getline(InFile, S)) {
		TotalChars+=S.length();
		TotalLines++;
	}
	cout << "Total characters: " << TotalChars << endl;
	cout << "Total lines: " << TotalLines << endl;
}
//--------------------------------------------------------------------------------
int main()
{
	ifstream InFile;
	lvpstring FileName;

	while (true) {
		cout << "Enter name of file (Enter to quit): ";
		getline(cin, FileName);
		if (FileName.length() == 0)
			break;
		InFile.open(FileName.c_str());
		if (InFile.fail())
			cout << "File cannot be opened" << endl;
		else {
			DisplayStats(InFile);
			InFile.close();
		}
	}
	return(0);
}
