Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.vbc.net!samba.rahul.net!rahul.net!a2i!bug.rahul.net!rahul.net!a2i!in-news.erinet.com!imci5!pull-feed.internetmci.com!news.internetMCI.com!newsfeed.internetmci.com!news.compuserve.com!newsmaster From: 100065.270@compuserve.com (Carlyle Sutphen) Newsgroups: comp.unix.bsd.misc,alt.unix.wizards,comp.unix.misc Subject: Re: How to write end of file character into file??! Date: Sat, 13 Apr 1996 01:06:41 GMT Organization: CompuServe Incorporated Lines: 30 Message-ID: <4klv2o$4dd@arl-news-svc-3.compuserve.com> References: <xsvarshney-0604962038290001@newshub.csu.net> <4kb6sv$399@is05.micron.net> <4khh63$a3@anorak.coverform.lan> NNTP-Posting-Host: ad31-188.compuserve.com X-Newsreader: Forte Free Agent 1.0.82 Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:712 alt.unix.wizards:3627 comp.unix.misc:21976 brian@awfulhak.demon.co.uk (Brian Somers) wrote: >Dwight Tovey (dwight@micron.net) wrote: >[stuff deleted] >: data_f = fopen( "input", "r" ); >: while( !feof( data_f )) { >: fread(....) >: ..... >: } >: fclose( data_f ); >Nope, you'd be better off writing >data_f = fopen( "input", "r" ); >while( fread(....), !feof( data_f ) ) { > ..... >} >fclose( data_f ) >And don't ever call me pedantic ! :-) ??? Why? Then even if fread was successfull in reading any data at the end of the file, if we asked for more than was read, the body of the while would be skipped! That is where the processing of the data read will be put. He had it right but needs to realize that EOF is a condition, not data.