/* * This program reads numbers from the file "numbers", determining * and printing the maximum number. */ #include int main () { FILE *f; /* file pointer */ float num, /* number to read in */ max; /* current maximum */ /* open the file for reading */ f = fopen ("numbers", "r"); /* get a number from the file */ fscanf (f, "%f", &num); /* assume this is the maximum number until we hear otherwise */ max = num; /* while we haven't reached the end of file... */ while (!feof (f)) { /* if the number we read in is bigger than max, * set max equal to it */ if (num > max) max = num; /* get another number, or possibly trigger end of file */ fscanf (f, "%f", &num); } /* close the file */ fclose (f); /* print the maximum */ printf ("maximum is %f\n", max); return 0; }