Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!asstdc.scgt.oz.au!nsw.news.telstra.net!act.news.telstra.net!imci3!imci4!newsfeed.internetmci.com!in2.uu.net!news.micron.net!dwight From: dwight@micron.net (Dwight Tovey) Newsgroups: comp.unix.bsd.misc,alt.unix.wizards,comp.unix.misc Subject: Re: How to write end of file character into file??! Date: 23 Apr 1996 14:44:36 GMT Organization: Wish I had some Lines: 45 Message-ID: <4liqck$2e6@is05.micron.net> References: <xsvarshney-0604962038290001@newshub.csu.net> <4l5le1$amd@is05.micron.net> <4l85m7$fjs@sv024.SanDiegoCA.ATTGIS.COM> <4lg9i8$8if@is05.micron.net> <4lgegj$oi3@web.nmti.com> Reply-To: dwight@micron.net NNTP-Posting-Host: dwight.boi.micron.net X-newsreader: xrn 8.01 Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:830 alt.unix.wizards:3712 comp.unix.misc:22191 In article <4lgegj$oi3@web.nmti.com>, peter@nmti.com (Peter da Silva) writes: |> Only if your code is broken: |> Never said it wasn't broken. Didn't put it out as how to use fgetc. Only said I've seen it in some code and the person involved couldn't figure out what was going on. Wasn't trying to say that what my fix was the "proper" one. ONLY WANTED TO POINT OUT FEOF! (grumble grumble nobody listens anymore) :) This whole discussion started with somebody who wanted to know what the Unix EOF character was, not how to use fgetc or read or any of the others. Some of us were only trying to point out the feof condition instead of using the return value as the test. After all, fgetc can return EOF for conditions other than feof. |> > char ch; |> > FILE *fp |> > |> > fp = fopen( "foo", "r" ); |> > while(( ch = fgetc( fp) ) > 0 ) { |> > putchar( ch ); |> > } |> |> See, the correct change to this code is to replace "char ch" with "int ch", |> as is described in the manuals. A change, but not necessarily the "correct" change. I have seen situations where it could be "better" to use a char type (usually in embedded controllers). Way back in college I had an instructor who claimed that any code that works is valid as long as you understand why it works and under what situations it won't work. |> |> Also, 0xFF is a valid text character. It's a lowercase y with dieresis. |> -- Now whos being pedantic? :) Should I specify only US-ASCII text? :) /dwight -- Dwight N. Tovey H&W Computer Systems, Inc. Software Specialist III 12438 W. Bridger St. Suite 100 dwight@hwcs.com Boise, ID. 83713 or dwight@micron.net (208)377-0336 I didn't claw my way to the top of the food chain to eat vegetables!!