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!spool.mu.edu!howland.reston.ans.net!swrinde!cssun.mathcs.emory.edu!gatech!news.mathworks.com!uunet!in2.uu.net!nwnews.wa.com!news.halcyon.com!usenet
From: moonbeam@catmanor.com (William Julien)
Newsgroups: comp.unix.bsd.misc,alt.unix.wizards,comp.unix.misc
Subject: Re: How to write end of file character into file??!
Date: 7 Apr 1996 18:21:22 GMT
Organization: Computing Cat Manor
Lines: 38
Message-ID: <4k9132$6vj@news.halcyon.com>
References: <xsvarshney-0604962038290001@newshub.csu.net>
NNTP-Posting-Host: blv-pm0-ip25.halcyon.com
X-Newsreader: knews 0.9.4
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:638 alt.unix.wizards:3582 comp.unix.misc:21832
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?
>
EOF is not a character but a return value provided my the function. Files
in unix are defined as "a stream of bytes". If an end of file marker is
is up to the application to implement.
so this writes, then reads it back...
data=fopen("input", "a");
fprintf(data_f, "%s\n", var1);
fflush(data);
data=fropen("input", "r");
fscan(data,"%s",var2);
By the way... This is more a C question than a unix one.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/\_/\ Practice random kindness William Julien
/\ / o o \ and senseless acts of beauty moonbeam@catmanor.com
//\\ \~(*)~/ http://www.halcyon.com/moonbeam/pacinn/