Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.ecn.uoknor.edu!news.ysu.edu!usenet.ins.cwru.edu!agate!news.ossi.com!netserv.com!news.mathworks.com!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: 8 Apr 1996 14:12:47 GMT Organization: Wish I had some Lines: 43 Message-ID: <4kb6sv$399@is05.micron.net> References: <xsvarshney-0604962038290001@newshub.csu.net> 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:629 alt.unix.wizards:3577 comp.unix.misc:21817 In article <xsvarshney-0604962038290001@newshub.csu.net>, xsvarshney@ccvax.fullerton.edu (S. Varshney) writes: |> |> |> I have the following code to write to a file... |> |> Input of variable is done by: |> |> data_f=fopen("input", "a"); |> fprintf(data_f, "%s\n", var1); |> |> Now I'm trying to read this file, using fopen("input","r"); |> |> The problem is, I can't seem to get a handle on detecting the eof char... |> so as to be able to printf correctly. Any suggestions on how to write the |> file so that an EOF char is written on the file, so that I can read the |> EOF correctly? |> |> The machine is Unix 5.5 Thanks! |> |> |> -Suvrit |> xsvarshney@ccvax.fullerton.edu Others have already commented about the EOF in Unix. One other thing you can do when reading the file is use the 'feof()' to check for the EOF condition before you do the read. Possibly something like this: data_f = fopen( "input", "r" ); while( !feof( data_f )) { fread(....) ..... } fclose( data_f ); /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!!