// Lab #8: File It Away // Program: READCHAR.CPP // This program reads all of the character values in // a user-specified file, and simply writes them back // to the screen in the same format. // Note the use of a slightly different strategy for // testing for the end of each line and the end-of-file // marker. // This is possible because we are reading for characters // this time, not integers. // Your task is to modify this code so that it counts // the number of lines and the number of 'e's in the // input file. READ THE COMMENTS CAREFULLY. Understand // what this basic skeleton is doing before you try to // modify it. #include #include #include #include "boolean.h" void main() { char filename[81]; ifstream fin; // Declare and define the input file stream fin. cout << "Please enter a file name: "; cin >> filename; fin.open(filename); while (fin.fail()) { cerr << "Cannot open " << filename << " for reading." << endl; cout << "Please re-enter the file name: "; cin >> filename; fin.open(filename); } cout << endl; boolean MoreLines = TRUE; boolean MoreCharacters; char CurrentCharacter; while (MoreLines) { MoreCharacters = TRUE; while (MoreCharacters) { if (fin.get(CurrentCharacter)) { // process CurrentCharacter on current line cout << CurrentCharacter; if (CurrentCharacter = '\n') { // current line has no more characters MoreCharacters = FALSE; } } else { // no more characters at all MoreCharacters = FALSE; MoreLines = FALSE; } } // finish up processing of current line } // finish up overall processing }