Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 10 months ago.
fscanf and feof not working issue: printing 0.00 values
hi Ralph Fulchiero,
I am using fscanf function to get values from the afe.csv file stored in SD card reader.
i am not able to read the values and getting 0 for all parameters when printed on screen.
please find below the code for reference.
void read_file()
{ FILE *tmp; tmp= fopen("/sd/afetest.csv", "r"); if(tmp==NULL) represent file is present { serial.printf("file not present\n"); } {
while(!feof(tmp)) { int z=0; z = vfscanf(tmp,"%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \r\n",&Total_loop_time1,&cellvolt[0],&cellvolt[1],&cellvolt[2],&cellvolt[3],&cellvolt[4],&cellvolt[5],&cellvolt[6],&cellvolt[7],&cellvolt[8],&cellvolt[9],&cellvolt[10],&cellvolt[11],&cellvolt[12],&cellvolt[13],&cellvolt[14], &bat_volt,&battery_current,&Bat_Ah,&soc,&temp_deg3,&temp_deg2,&temp_deg1); serial.printf("\n\n z is %d \r\n ", z); {
} } } fclose(tmp); }
1 Answer
6 years, 9 months ago.
Hi Imran,
It's not obvious what the problem is, so we suggest first reading the file line by line with fgets() or reading the individual entries as strings to make sure that you are at least properly reading from the file!
Interestingly we happened to come across a very similar question from 2011:
Good Luck,
Ralph, Team Mbed
hi Ralph Fulchiero,
Can you please help me with this.
Thanks Imran
posted by mohd imran khan 29 Nov 2018