This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: scanf and spaces


Andreas Jaeger <aj@suse.de> writes:

|> Werner reported a problem to me that can be shown by the appended test
|> case for our testsuite.  He claimed that this is broken in 2.2.x but
|> worked in older glibc releases.
|> 
|> ISO C 99 states for scanf:
|> 
|>        [#8]  Input  white-space  characters  (as  specified  by the
|>        isspace function)  are  skipped,  unless  the  specification
|>        includes a [, c, or n specifier.241)

This does not fit here.  This is the paragraph that matches here:

       [#6] A directive that is an ordinary multibyte character  is
       executed  by  reading the next characters of the stream.  If
       any of those characters differ from the ones  composing  the
       directive,   the  directive  fails  and  the  differing  and
       subsequent characters remain unread.

|> +    res = sscanf ("int=11 float=22.22", "int=%dfloat=%f", &i, &f);

sscanf reads "11" via %d, then tries to match "f", but the next character
is " " -> fail.  The expected return values is 1.

Andreas.

-- 
Andreas Schwab                                  "And now for something
SuSE Labs                                        completely different."
Andreas.Schwab@suse.de
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]