Code tags for code please, they make the unreadable readable. [ code ] stuff [ /code ] without the extra spaces.
You get 'floating point error' when you divide by zero, check to see if things are getting parsed the way you expect.
You do not need to use fgetc to read in text data! Try scanf. Or better yet, sscanf. Read in data one line at a time then feed it through scanf to get what you want in one go.
Code:
char buf[512], garbage[512];
if(fgets(buf, 512, fp)==NULL0
{
fprintf(stderr, "Can't read first line\n");
return(1);
}
if(sscanf(buf, "%d", &load) != 1)
{
fprintf(stderr, "Can't get load value\n");
return(1);
}
while(fgets(buf, 512, fp)!=NULL)
{
if(sscanf(buf, "%s %d %d", garbage, &weight, &value) != 3)
{
fprintf(stderr, "Couldn't parse line '%s'\n", buf);
continue;
}
do_stuff();
}