FidoNet Echomail Archive
aust_c_here

<<< Previous Index Next >>>

From: Joshua Marshall
To: Paul Edwards
Date: 1997-02-16 08:59:42
Subject: Re: Borland C bug ?!?

Hello Paul,
 In a message dated 13 Feb 97 you wrote to me :

 JM>>>> while (!feof(fp))
 JM>>>> {
 JM>>>> fgets(s,500,fp);
 PE>>>    ^^^^^^^^^^^^^^^^
 JM>>>> blah blah
 JM>>>> }

 PE>>> You're not checking the return from fgets().  How will you know if
 PE>>> you hit EOF?  You have a bug.  BFN.  Paul.

 JM>> I check in the line above - feof(fp).

 PE> Like I say, you have a bug.  !feof(fp) will be true, because you haven't
 PE> hit EOF, fgets() will return NULL, because it reaches EOF when reading
 PE> the line, and you ignore that return code, and use s regardless.  s
 PE> will have junk in it.

Step 1: Check for EOF
Step 2: If not at EOF, read data.
Step 3: process data
Step 4: go to Step 1.

This is what I am doing.  If I am not at EOF at the start then I will not
be at EOF when I read the data.  Thus I will need to read in data, since
there is some left to process.  I cannot see how s will have junk in it as
it is terminated with a \0 at the end.

If I checked the EOF status from fgets() I may still have data that needs
to be processed!!!  If I stopped processing there I would miss it entirely.
 _That_ is a bug.

 Josh Marshall   Fidonet   3:640/201.14
  ->MEMBER<-     Internet  joshua{at}st.net.au
  Team Amiga     Amiganet  41:400/869.14

... High explosives and school don't mix. --Bart Simpson.
--- Mail Manager 1.22x/p #1219
 * Origin: Borderline Technologies (3:640/201.14{at}fidonet)
SEEN-BY: 50/99 54/99 620/243 623/630 640/201 201 206 217 222 230 238 254 297
SEEN-BY: 640/305 309 370 375 386 547 820 821 822 823 837 890 690/660 711/413
SEEN-BY: 711/430 934 712/311 407 505 506 517 623 624 704 841 713/317 714/906
SEEN-BY: 800/1
@PATH: 711/934


<<< Previous Index Next >>>