You have a file with rows of numbers. Each row has a set number of Integers and you have to find the average for each row. The rows are unknown but we know how many integers there are in each row.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>

#define INTEGERS 3

int main(){
    int i=0,num;
    float average=0;
    FILE *input;
   
    if(!(input=fopen("14_5_sel19.txt","r"))){
        puts("Error opening file! Exiting");
        return 1;
    }
   
    while(fscanf(input,"%d",&num)==1){
        i++;
        average+=num;
        if(i==INTEGERS){
            printf("average oros: %.2f\n",average/INTEGERS);
            i=0;
            average=0;
        }  
    }
    fclose(input);
    return 0;
}