🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #7139

Re: feof does not work: HELP!

#7139
From: Peter da Silva
Date: Sat, 01 Dec 1990 01:22
15 lines
1261 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   {
>    42    printf ("%2d. ",y+1);        /* print line number */
>    43    while ((ch=fgetc (in))!='@') /* read until separator encountered */
                      ^^^^^
What happens if you hit EOF here?

After reading the final line you're going to sit in an infinite loop comparing
EOF with '@'. The simplest fix is to insert "!feof(in) && " before "(ch=fgetc",
but I'd read the whole line into memory and manipulate it there. Not quite as
efficient, maybe, but I/O time is likely to dominate in this application.
-- 
Peter da Silva.   `-_-'
<peter@sugar.hackercorp.com>.
Technical Details
Message-ID: <7172@sugar.hackercorp.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!lavaca.uh.edu!menudo.uh.edu!nuchat!sugar!peter
References: <4413@ruuinf.cs.ruu.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!lavaca.uh.edu!menudo.uh.edu!nuchat!sugar!peter
From: peter@sugar.hackercorp.com (Peter da Silva)
Newsgroups: comp.sys.amiga.tech
Subject: Re: feof does not work: HELP!
Keywords: C trouble
Message-ID: <7172@sugar.hackercorp.com>
Date: 1 Dec 90 01:22:26 GMT
References: <4413@ruuinf.cs.ruu.nl>
Reply-To: peter@sugar.hackercorp.com (Peter da Silva)
Organization: Sugar Land Unix - Houston
Lines: 15