0

How can I store the values in a text file in a 2D array and call out the smallest number on each column in C?

I have a file thats filled with numbers in 5 colums and 196 rows I want the program to read what's inside the file and print out the min and max values on each column in C.

3rd Jun 2022, 12:23 PM
Kerem Said Demirboğa
Kerem Said Demirboğa - avatar
1 ответ
0
I don't see the need to store all the numbers, if you only need the min and max for each column. #define NC 5 #define NR 196 int min[NC], max[NC], i, j, nr; FILE *f = fopen("filename.txt", "rt"); for(j = 0; j < NC; ++j) { fscanf(f, "%d", &nr); min[j] = max[j] = nr; } for(i = 1; i < NR; ++i) for(j = 0; j < NC; ++j) { fscanf(f, "%d", &nr); if(min[j] > nr) min[j] = nr; if(max[j] < nr) max[j] = nr; } That's it, at this point you should have the min and max for each of the 5 columns.
4th Jun 2022, 12:56 PM
lion
lion - avatar