I am currently using function fscanf to parse a file with some char and float point. I confirmed the results by printing them out and memory check with valgrind. Now, the printing is correct but there are always a definitely loss of memory.
This is a sample code:
FILE* table;
table = fopen("table", "r");
double mass;
while (fscanf(table, %lf ", &mass) != EOF){
printf("mass: %lf\n", mass);
}
and the valgrind with --leak-check=full
option says:
==7104== 513 bytes in 1 blocks are definitely lost in loss record 52 of 62
==7104== at 0x100008EBB: malloc (in /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==7104== by 0x1001EF66C: __parsefloat_buf (in /usr/lib/system/libsystem_c.dylib)
==7104== by 0x1001ED9EF: __svfscanf_l (in /usr/lib/system/libsystem_c.dylib)
==7104== by 0x1001E1492: fscanf (in /usr/lib/system/libsystem_c.dylib)
==7104== by 0x100000F3F: main (in ./prtm)
I think it's the problem of format. I've also tried to use %f
and float
but just get more similar error.
Can anyone tell me what goes wrong?