Feof


 
Thread Tools Search this Thread
Top Forums Programming Feof
Prev   Next
# 1  
Old 12-04-2001
Question Feof

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?
Code:
#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
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question
while(n)						       Tcl Built-In Commands							  while(n)

__________________________________________________________________________________________________________________________________________________

NAME
while - Execute script repeatedly as long as a condition is met SYNOPSIS
while test body _________________________________________________________________ DESCRIPTION
The while command evaluates test as an expression (in the same way that expr evaluates its argument). The value of the expression must a proper boolean value; if it is a true value then body is executed by passing it to the Tcl interpreter. Once body has been executed then test is evaluated again, and the process repeats until eventually test evaluates to a false boolean value. Continue commands may be exe- cuted inside body to terminate the current iteration of the loop, and break commands may be executed inside body to cause immediate termi- nation of the while command. The while command always returns an empty string. Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the while command starts execut- ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter- ation), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10: set x 0 while {$x<10} { puts "x is $x" incr x } SEE ALSO
break(n), continue(n), for(n), foreach(n) KEYWORDS
boolean value, loop, test, while Tcl while(n)