I'm stuck at this where I need to find the highest average number inside a text file with an unknown amount of data. The data inside the txt is like this
id group score
2203 1 33
5123 2 58
3323 3 92
5542 2 86
....
....
and the file keeps going.
I'm currently trying to create a struct and then store the values inside of it, but I cannot determine the size of struct since the file has unknown amount of data and it might change every run.
What I tried is this
while(!feof(fptr)) {
for(i = 0; i < sizeoffile; i++ ) { // here i should add the size or the amount of data.
fscanf(fptr,"%d %d %d",&p[i].num, &p[i].grp, &p[i].score);
}
}
I tried adding a counter inside the while loop to get the amount of data but it doesn't work. Im not sure if i need to use malloc or something else.
Example run: code read the following file
1312 1 30
1234 1 54
2931 2 23
2394 2 99
9545 3 95
8312 3 100
8542 4 70
2341 4 56
1233 1 70
2323 1 58
output
group 3 has the highest average of 97