ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/25/01:15:10

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Date: Thu, 25 Apr 2002 09:13:36 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: "Goh, Yong Kwang" <gohyongkwang AT hotmail DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: detecting EOF when using fscanf()
In-Reply-To: <aa819p$tge$1@coco.singnet.com.sg>
Message-ID: <Pine.SUN.3.91.1020425091055.17284F@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Thu, 25 Apr 2002, Goh, Yong Kwang wrote:

> tMain
> tMain
> 
> D:\TEMP>
> ---END---
> 
> Notice the last token "tMain" got printed twice which infers that the loop
> was repeated another 1 last time after the last token.

That's expected behavior for the code you wrote.

> So is there any easy way to overcome this problem, or do I have to do the
> tokenizing and parsing character by character using fgetc instead for the
> program to work more reliably?

It's generally recommended to use fgets (followed by sscanf) in such 
cases, not fscanf.  If you must use fscanf, you will have to design your 
format conversion string carefully (for example, include a \n in it), 
and/or look at the value fscanf returns, instead of ignoring it.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019