/* # Copyright (C) 2005 Andrew E Firth, University of Otago, Dunedin, # New Zealand, aef(at)sanger.otago.ac.nz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License (version 2) as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. */ #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"; }