Sponsored Content
Full Discussion: Feof
Top Forums Programming Feof Post 11405 by primal on Tuesday 4th of December 2001 07:27:38 PM
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
 
feof(3) 						     Library Functions Manual							   feof(3)

NAME
feof - Tests EOF on a stream LIBRARY
Standard C Library (libc) SYNOPSIS
#include <stdio.h> int feof( FILE *stream); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: feof(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the input stream. DESCRIPTION
The feof() function tests the EOF (end-of-file) condition on the specified stream. NOTES
[Tru64 UNIX] The feof() function may be a macro (depending on the compile-time definitions used in the source). Consequently, you cannot use this interface where a function is necessary; for example, a subroutine pointer cannot point to it. RETURN VALUES
If EOF has previously been detected reading the input stream specified by the stream parameter, a nonzero value is returned. Otherwise, a value of 0 (zero) is returned. RELATED INFORMATION
Functions: ferror(3), fileno(3), clearerr(3), fopen(3) Standards: standards(5) delim off feof(3)
All times are GMT -4. The time now is 03:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy