*BSD News Article 65543


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.bhp.com.au!mel.dit.csiro.au!munnari.OZ.AU!spool.mu.edu!howland.reston.ans.net!newsfeed.internetmci.com!in1.uu.net!brighton.openmarket.com!decwrl!waikato!status.gen.nz!pinnacle.co.nz!not-for-mail
From: jonc@pinnacle.co.nz (Jonathan Chen)
Newsgroups: comp.unix.bsd.misc,alt.unix.wizards,comp.unix.misc
Subject: Re: How to write end of file character into file??!
Date: 11 Apr 1996 09:08:25 +1200
Organization: Pinnacle Software Ltd, Auckland, New Zealand
Lines: 24
Message-ID: <4kh809$5s2@tui.pinnacle.co.nz>
References: <xsvarshney-0604962038290001@newshub.csu.net>
NNTP-Posting-Host: tui.pinnacle.co.nz
X-Newsreader: NN version 6.5.0 #3 (NOV)
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.misc:683 alt.unix.wizards:3602 comp.unix.misc:21920

In <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?

Check out fscanf(3). Check its return code against <stdio.h>'s EOF value.

"UNIX don't need no steenkin' EOF character"
-- 
Jonathan Chen                          e-mail : jonc@pinnacle.co.nz
  Pinnacle Software Ltd                Voice  : +64.9.489.7020
  Auckland, New Zealand                Fax    : +64.9.489.7040