/* Name: PrintReversedArray Copyright: Author: Professor Langsam Date: 18/03/06 22:03 Description: Prints and counts the numbers in an external file in reversed order. */ #include #include #include //include library for file processing const int MAXNUMBER= 1000; using namespace std; int main(int argc, char *argv[]) { int i, count, number[MAXNUMBER]; ifstream infile; //create the file infile for input infile.open("NumbersData.txt"); //open the file if ( !infile.is_open() ) { //check to see if file was opened // The file could not be opened cout << endl << "ERROR: Unable to open file" << endl; system ("PAUSE"); exit(1); } i = 0; while (!infile.eof() && infile >> number[i]) ++i; count = i; cout << "\nThe array contains " << count << " elements." << endl; for (i = count-1; i >= 0; i--) cout << number[i] << endl; infile.close(); //close the file system("PAUSE"); return EXIT_SUCCESS; }