I'm working on a segment of a program where I have to read doubles from a .dat file I created which holds 12 doubles which looks like:
10.0
20.0
30.0
40.0
50.0
60.0
70.0
80.0
90.0
100.0
110.0
120.0
Here is my code:
double readSales(FILE *input, double sales[])
{
int count = 0, n;
double s;
n = fscanf(input, "%lf", &s);
sales[0] = s;
while(n == 1)
{
n = fscanf(input, "%lf", &s);
count++;
sales[count] = s;
}
}
This works fine but I don't think it is well written due to having to declare the first element of the array. The issue is without the declaration, I just get a 0.0 as the first element of the array. Thank you for any feedback.