Here's the text file:
7
905 177 738 891 912 853 271
607 894 958 848 636 691 309
953 888 153 485 969 483 379
151 196 106 387 115 569 788
The first number denotes the number of columns or elements in each row.
The problem I'm having is that my program prints out the minimum and maximum value of each line (excluding the first line) just fine but then it seems to print out another set of values at the end that I don't need. For example here's my output:
min: 177 max: 912
min: 309 max: 958
min: 153 max: 969
min: 106 max: 788
min: 151 max: 788 <--------- UNNECESSARY OUTPUT
And here's the program:
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- void open_file ();
- int main()
- {
- open_file();
- return 0;
- }
- void open_file()
- {
- int first_num, num, max, min, loop, update;
- FILE *fp;
- int columns;
- fp = fopen("stats_data.txt", "r");
- loop = fscanf(fp, "%d", &columns);
- while (loop != EOF)
- {
- update = (columns - 1);
- fscanf(fp, "%d", &first_num);
- max = first_num;
- min = first_num;
- while (update > 0)
- {
- loop = fscanf(fp, "%d", &num);
- if (num > max)
- max = num;
- if (num < min)
- min = num;
- update = update - 1;
- }
- printf("min: %d ", min);
- printf("max: %d ", max);
- printf("\n");
- }
- }