Text file statistics

Write a program, which takes a text file as its input and produces another text file containing the
following information:
 total number of characters
 total number of words
 length of the longest word
 length of the shortest word
 average word length.
Results should be automatically saved in the text file which name is generated as:
inputFileName_out.txt, where inputFileName is the name of the input text file.


I started somehow pls help me to end PLS!!!

#include "std_lib_facilities.h"

using namespace std;
int main()
{
char characters; int counter = 0, counterW = 0;
string words;
ifstream inpFile;
inpFile.open("text.txt");
if (inpFile.is_open()) {
while (inpFile >> characters) counter++;
cout << counter << " characters\n";


}
else
error("File is not open");



inpFile.close();
return 0;

}
Last edited on
Should you count whitespace as characters?
Yes, spaces should be counted pls
Then it looks like counting all characters could be achieved with seekg/tellg:
http://www.cplusplus.com/reference/istream/istream/seekg/

The other stats you get from taking input one word at a time.
* Count of words
* Minimum of word.length()
* Maximum of word.length()
* Sum of word.length()
Topic archived. No new replies allowed.