Date: Wed, 10 May 2000 23:02:41 -0400 Message-Id: <200005110302.XAA24554@envy.delorie.com> From: DJ Delorie To: shinelight AT crosswinds DOT net CC: djgpp AT delorie DOT com In-reply-to: <3.0.6.32.20000510204858.007b6e40@pop.crosswinds.net> (shinelight AT crosswinds DOT net) Subject: Re: feof(FILE *) NOT portable... References: <8empao$5k6$1 AT nnrp02 DOT primenet DOT com> <390ef9f9$0$72098 AT SSP1NO17 DOT highway DOT telekom DOT at> <8emvhq$7mn$1 AT nnrp03 DOT primenet DOT com> <3 DOT 0 DOT 6 DOT 32 DOT 20000505015633 DOT 007b2210 AT pop DOT crosswinds DOT net> <3 DOT 0 DOT 6 DOT 32 DOT 20000510204858 DOT 007b6e40 AT pop DOT crosswinds DOT net> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Well, after a good several hours of debugging, I finally discovered > that feof(FILE *) does NOT work the same under DJGPP as it does > under other compilers. I compiled your program under both DJGPP and Linux. They do exactly the same thing. The reason there's an extra character at the end of the last line is because YOU PUT IT THERE. x[0] = fgetc(fp); The first time you try to read past the end of the file, fgetc returns -1, which you coerce to (char)0xff and append that to the string. The right way to do what you want is to add a check after the fgetc, rather than (or, if you want to support Borland's buggy feof, in addition to) after the strcat. > Make sure the next release of DJGPP fixes this bug. No. It's not a bug, and besides, you have no right to tell us what to do. The only thing you have the right to do is fix it yourself if it's that important to you.