delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/09/02/20:30:22

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Trace-PostClient-IP: 68.147.131.211
From: Brian Inglis <Brian DOT Inglis AT SystematicSW DOT Invalid>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: scanf: strange behavior?
Organization: Systematic Software
Message-ID: <9ccfj0hufuh2nii5jfjqlqgbf3g7b34mo6@4ax.com>
References: <20040902144152 DOT GH6858 AT webhome DOT cz> <2pp00iFnf7nsU1 AT uni-berlin DOT de> <41374c9c$0$173$cc7c7865 AT news DOT luth DOT se> <20040902184005 DOT GA23943 AT webhome DOT cz> <41378A42 DOT 5040801 AT acm DOT org> <200409022144 DOT i82LiDLe005751 AT envy DOT delorie DOT com> <20040902221157 DOT GB7970 AT webhome DOT cz> <200409022230 DOT i82MUuqE006471 AT envy DOT delorie DOT com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Lines: 52
Date: Fri, 03 Sep 2004 00:21:05 GMT
NNTP-Posting-Host: 24.71.223.147
X-Complaints-To: abuse AT shaw DOT ca
X-Trace: pd7tw1no 1094170865 24.71.223.147 (Thu, 02 Sep 2004 18:21:05 MDT)
NNTP-Posting-Date: Thu, 02 Sep 2004 18:21:05 MDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Thu, 2 Sep 2004 18:30:56 -0400 in comp.os.msdos.djgpp, DJ Delorie
<dj AT delorie DOT com> wrote:

>
>> -- I'm becoming more and more confident, that it's actually
>> inconsistent with the current implementation.
>> 
>> To return EOF, the input has to end *before* the first item
>> converted/assigned, because when it has to end otherwise?  It has to
>> end sometime...  No word about conversion items pending.
>
>The documentation is vague (heck, the standard is a little vague too).
>The problem is that it doesn't say what happens when they're
>successful conversions AND input ends prematurely.  The normal case is
>that you have a conversion for all your format specifiers before input
>ends.  The other two cases are a conversion error (wrong input) or end
>of string (no input).

ISTM the standard clearly specifies only input failure *before* any
conversion occurs results in EOF: any matching failure results in the
number of matched, converted and assigned items being returned, which
may be zero:

"7.19.6.2#16 The fscanf function returns the value of the macro EOF if
an input failure occurs before any conversion. Otherwise, the 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." 

>The appropriate test cases are thus, for "%d %d":

IMHO according to info and standard, results should be:
>    ""
input failure - terminator - returns EOF
>    "x"
matching failure - returns 0
>    "5"
input failure - terminator - returns 1
>    "5 x"
matching failure - returns 1
>    "5 5"
success - returns 2
>    "5 5 x"
success - returns 2 - " " scanned and pushed back - "x" unscanned
>
>The first and third are the problem cases here.

-- 
Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada

Brian DOT Inglis AT CSi DOT com 	(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address		use address above to reply

- Raw text -


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