Date: Sun, 7 Apr 1996 08:19:49 +0200 (IST) From: Eli Zaretskii To: "Alexander V. Lukyanov" 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: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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.