So Im trying to read some variables from a text file - stored like this:
2.503, 0.500, 1.200, 2.693, 4.325, 6.131, 8.125,
5.000, 21.000
2.503, 0.500, 1.200, 2.693, 4.325, 6.131, 8.125,
4.938, 21.000
The second last value has varied, see?
Here is my code
Code:
if ( &file1 != NULL )
{
while(f_gets(buffer, sizeof(buffer), &file1)!= NULL)
{
res = sscanf(buffer, "%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf\n", &data[0],&data[1],&data[2],&data[3],&data[4],&data[5],&data[6],&data[7],&data[8]);
printf_P(PSTR("data: "));
printf("%.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8]);
}
f_close(&file1);
I know its not quite how it would be done on C on a pc - im programming a microcontroller, so the filesystem commands are very slightly different.
It works to a certain degree - I get this back
data: 2.503, 0.500, 1.200, 2.693, 4.325, 6.131, 8.125,
4.938, 21.000
data: 2.503, 0.500, 1.200, 2.693, 4.325, 6.131, 8.125,
4.938, 21.000
In other words, its reading the last line fine, but doesnt get the first. Any idea what tells the code to grab each line, rather than only the last one?