I need some help. Either I'm wrong, or the compiler is broken. I got this program:
Code:
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *fp;
char death[] = "bob.txt";
float l1=0, l2=0, l3=0, l4=0, l5=0;
if ( (fp = fopen(death, "r")) == NULL)
{
printf("error opening file.");
}
else
{
fscanf(fp, "%f, %f, %f, %f, %f", &l1, &l2, &l3, &l4, &l5);
printf("%f, %f, %f, %f, %f", l1, l2, l3, l4, l5);
fclose(fp);
getch();
}
}
The file bob.txt looks like this:
Code:
123.45 87.001
100.02
0.00456 1.0005
But when the program executes, it outputs this:
123.449997, 0.000000, 0.000000, 0.000000, 0.000000
I have gone through the program over and over and can't figure out why it's not going to the next number in the file. Anyone have any ideas for me?