*BSD News Article 65204


Return to BSD News archive

Newsgroups: comp.unix.bsd.misc,alt.unix.wizards,comp.unix.misc
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!genmagic!sgigate.sgi.com!swrinde!howland.reston.ans.net!ix.netcom.com!netcom.com!tporczyk
From: tporczyk@netcom.com (Tony Porczyk)
Subject: Re: How to write end of file character into file??!
Message-ID: <tporczykDpHDC2.427@netcom.com>
Organization: ITRC
References: <xsvarshney-0604962038290001@newshub.csu.net>
Date: Sun, 7 Apr 1996 07:12:02 GMT
Lines: 27
Sender: tporczyk@netcom20.netcom.com
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:626 alt.unix.wizards:3573 comp.unix.misc:21800

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!

There is no such character.  It's the OS that tells you through the
EOF "character" that you have reached the end of stream.  What do you
use to read the file (you only said how you open it)?  If you use getc()
or fgetc(), you can check if the character is EOF.  Then you will know
you've reached the end.

t.
---------------------------------------------------------------------------
Tony Porczyk     *     tporczyk@netcom.com     *     San Jose,  California
GIT/ED d++$(!d) s++:++ a? C++++ UBSL++++$ P+ E--- W(--) N++ !k w-- M- V? b-
PS+++@ PE++ O X-- Y++@ PGP-- t+@ 5-- R* D---- !e>e++@ h* y** r+++(*)+++(*)> 
---------------------------------------------------------------------------