// FILENAME: scores.cpp // Written by Darin Gillis // gillisd@colorado.edu // Recitation # 023, Mondays 1:00 - 1:50 // #include // For EXIT_FAILURE, EXIT_SUCCESS #include // For external file streams #include // For cin, cout, cerr #include // For isspace // PROTOTYPES // Reads max number of numbers from the given file and // tallys the results of the numbers into the tally array void readscores(char filename[ ], int tally[ ], int max); // Gets one integer from input file and return it to program int getinteger(ifstream& ins); // Reads and discard "white space" from file void eatspace(ifstream& ins); //************************* Main **************************** int main() { // readscores(); return EXIT_SUCCESS; } //---------------------------------------------------------- // Reads max number of numbers from the given file and // tallys the results of the numbers into the tally array void readscores(char filename[ ], int tally[ ], int max) { ifstream ins; // Input file stream containing bunch of ints int num; // holds temp values for read integer // Open input file, exit on any error cout << "Please type the file name of the grade data: "; cin >> filename; ins.open(filename); if (ins.fail()) { cerr << "<<< - ERROR: Cannot open " << filename << " for input. - >>>" << endl; return EXIT_FAILURE; } // Take each integer from input file, // decode it, and // write it to the output eatspace(ins); while (!ins.eof()) { // gets int num = getinteger(ins); letter_count++; eatspace(ins); } ins.close(); return; } //---------------------------------------------------------- // Gets one integer from input file and return it to program int getinteger(ifstream& ins) { int next_integer; // integer read from ins ins >> next_integer; return next_integer; } //---------------------------------------------------------- // Reads and discard "white space" from file void eatspace(ifstream& ins) { while (isspace(ins.peek())) ins.ignore(); if (ins.peek() == EOF) ins.ignore(); return; }