Prelude's code with modification
Code:#include <cctype> ... while ( inFile.get ( c ) ) { cout<< c; if ( c == '\n' ) { linecount++; charcount = 0; // it's a new line so let's start counting from zero again } else if ( !isspace ( c ) ) charcount++; }