I'm having troubles with sscanf() function to read doubles. I have a comma separated text file like this:
ABC,DEF,0.465798,0.754314
GHI,JKL,0.784613,0.135264
MNO,OPQ,0.489614,0.745812
etc.
So first I get the line with fgets() and then I use sscanf() to get the two string and two double variables.
fgets(buffer, 28, file);
sscanf(buffer, "%4[^,],%4[^,],%lf[^,],%lf[^\n]", string1, string2, &double1, &double2);
printf("%s %s %f %f\n", string1, string2, double1, double2);
But the output is:
ABC DEF 0.465798 0.000000
GHI JKL 0.784613 0.000000
MNO OPQ 0.489614 0.000000
So somehow it doesn't scan the last float. I've tried %lf[^ \t\n\r\v\f,]
and just %lf
but it still doesn't work.