www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/29/09:48:37

Message-ID: <36615BB8.7FCDE53F@gmx.de>
Date: Sun, 29 Nov 1998 15:35:36 +0100
From: Christian Hofrichter <ChristianHofrichter AT gmx DOT de>
X-Mailer: Mozilla 4.07 [de]C-QXW0310J (Win95; I)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: problem with fseek and/or feof
Reply-To: djgpp AT delorie DOT com

I have a problem with "feof" and "fseek".
What I did, was the following.

#include<conio.h>
#include<stdio.h>

void main(void)
{
FILE *f;

clrscr();
f=fopen("binary_file","rb");    /*open files in binary-mode for reading
*/
if (f==NULL)                      /* check if file exists; if not print
error-message and exit */
    {
     printf("Error !\n");
     getch();
     exit(1);
     }

while(feof(f)==0)
{
fseek(f,1,SEEK_CUR);
}
fclose(f);
}

This program should increase the filepointer by one byte, everytime
the loop is executed until EOF is reached.
"feof" return 0 if the EOF is not reached. Otherwise it returns a
value, different from 0.
So the loop should be executed until "feof" says that EOF is reached,
shouldn't it ?
But it doesn't. The loop isn't aborted and has no end.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019