The program I am making is supposed to read in numbers from a text file and save the total number of numbers, the average value of the numbers in a struct.
I have a struct that looks like this:
struct seriepost {
int totnr;
int outnr;
float average;
};
And the function (unfinished) looks like this:
int read_data(FILE *tsin, struct seriepost serie[]) {
int x = 0;
float average = 0;
float in_last = 0;
while (!feof(tsin))
{
while (fscanf(tsin, "%f", &in_last) != 0.0)
{
serie[x].totnr += 1;
serie[x].medel = average/serie[x].totnr;
serie[x].outnr = average*1.05+average*0.95;
}
x += 1;
}
fclose(tsin);
return sizeof(serie);
}
The text file looks like this:
22.2 12.4 24.5 12.4.....
22.2 12.2 0.0
2.21 12.1 11.1 11.1....
1.1 0.0
Where 0.0 marks the end of a series.
Now i want the fscanf to read all the numbers until 0.0 then i want it to skip to the next array spot for the next series. So i have like serie[0], serie[1] with their own set of numbers and averages values etc.