Hi Everyone,
I'm having problems with feof
I've storing my variables inside a file, and then in another program, opening that file and recalling the information.
The problem im having is that it's repeating the last set of entries in my while loop.
(if i have one set of product no., quantity, and price in my file, it repeats it twice. if i have two sets or more in my file, it repeats the last set twice)
I think it has something to do with how i have my while(!feof(file)) set up.
Does anyone know what's going on?
#include[stdio.h]
FILE *invfile;
int prod, qty;
float price;
void main()
{
invfile = fopen("file.dat","r");
while(!feof(invfile))
{
fscanf(invfile,"%d %d %f", &prod, &qty, &price);
printf("Product No. = %d\n",prod);
printf("Quantity = %d\n",qty);
printf("Price = %.2f\n\n",price);
}
fclose(invfile);
}
Thanks!
primal