www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/07/00:35:30

Date: Sun, 7 Apr 1996 08:19:49 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "Alexander V. Lukyanov" <lav AT video DOT yars DOT free DOT net>
Cc: Broeker AT axp03 DOT physik DOT rwth-aachen DOT de, djgpp AT delorie DOT com
Subject: Re: bug sscanf when match fails ?
In-Reply-To: <199604031044.OAA28741@video.yars.free.net>
Message-Id: <Pine.SUN.3.91.960407081111.22284B-100000@is>
Mime-Version: 1.0

On Wed, 3 Apr 1996, Alexander V. Lukyanov wrote:

> Shouldn't scanf exit if match failed and eof is not reached?

The ANSI standard says this about f?scanf (in 7.9.6.2 and 7.9.6.4):

	"...  If there are insufficient arguments for the format, the 
	behavior is undefined.  If the format is exhausted while 
	arguments remain, the excess arguments are evaluated (as always) 
	but are otherwise ignored.

	... The `fscanf' function returns the value of the macro EOF if 
	an input failure occurs before any conversion.  Otherwise, the 
	`fscanf' function returns the number of input items assigned, 
	which can be fewer than provided for, or even zero, in the event 
	of an early matching failure."

For `sscanf' it says the same (7.9.6.6) but also adds:

	"...  Reaching the end of the string is equivalent to 
	encountering end-of-file for the `fscanf' function.  If copying 
	takes place between objects that overlap, the behavior is 
	undefined." 

I guess reaching the end of the string in `sscanf' is the only equivalent 
of an ``input failure'' too.

- Raw text -


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