// This software is Copyright (C) 2005 by Andrew Firth, University of Otago, // Dunedin, New Zealand. All rights reserved. #include #include #include #include #include #include using namespace std; int main(int argc, char* argv[]) { if (2 != argc) { cerr << "Usage: '" << argv[0] << " file_name'.\n"; exit(EXIT_FAILURE); } int i, nlines; double min, max, temp; ifstream infile(argv[1]); if (!infile) { cerr << "Aborting: can't find file '" << argv[1] << "'.\n"; exit(EXIT_FAILURE); } nlines = -1; while (infile.ignore(1000, '\n')) { ++nlines; } infile.clear(); infile.seekg(0); if (0 == nlines) { cerr << "Aborting: file '" << argv[1] << "' is empty.\n"; exit(EXIT_FAILURE); } infile >> temp; min = temp; max = temp; for (i = 1; i < nlines; ++i) { infile >> temp; if (min > temp) { min = temp; } if (max < temp) { max = temp; } } cout << min << " " << max << "\n"; }