Article View: comp.sys.amiga.tech
Article #7358Re: feof does not work: HELP!
From: Andrew Phillips
Date: Mon, 10 Dec 1990 02:53
Date: Mon, 10 Dec 1990 02:53
37 lines
2016 bytes
2016 bytes
In article <4413@ruuinf.cs.ruu.nl> ptavoly@cs.ruu.nl (Peter Tavoly) writes:
> 40 while (!feof(in)) /* <- this is where the trouble starts :( */
> 41 {
> 43 while ((ch=fgetc (in))!='@') /* read until separator encountered */
> 44 putchar (ch); /* and output characters one by one */
> 46 fgets (line [y],74,in); /* read rest of line for later use */
> 47 if (feof(in)) return;
> 49 } /* while */
>Now the problem is that AztecC 5.0a somehow doesn't recognize the 'feof' ...
Your trouble is that feof() does not return 1 until after you try
reading PAST the end of file. So feof(in) is not true until after
you read the first character of the next line (assuming you have a
line-feed at the end of the last line of your file).
>... however the program keeps printing the character 255
>(an y with an umlaut on top) endlessly.
>I could try to look for a character 255 but this is not a nice way, and
>suppose that this character appears in your text, (as in Queensryche..:).
>In case of binaries it is even more likely to appear.
The character 255 comes from fgetc() returning -1 (fgetc returns an
INT) to indicate eof (or error) and this being converted to a char
when assigned to ch. It would be safer to make ch an int and check
for ch being -1 after each call to fgetc().
So I would say that Aztec C feof() is OK, although I haven't bothered
to test it.
Andrew.
--
Andrew Phillips (andrew@teslab.lab.oz.au) Phone +61 (Aust) 2 (Sydney) 289 8712
Technical Details
Message-ID:
<1164@teslab.lab.OZ>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!pta!teti!teslab!andrewReferences:
<4413@ruuinf.cs.ruu.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!pta!teti!teslab!andrew From: andrew@teslab.lab.OZ (Andrew Phillips) Newsgroups: comp.sys.amiga.tech Subject: Re: feof does not work: HELP! Summary: Aztec C feof() is OK Message-ID: <1164@teslab.lab.OZ> Date: 10 Dec 90 02:53:34 GMT References: <4413@ruuinf.cs.ruu.nl> Reply-To: andrew@teslab.lab.oz.au (Andrew Phillips) Organization: Technology Evaluation Section, L.A.B., Sydney Lines: 37