delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/06/24/09:57:52

From: colin AT fu DOT is DOT saga-u DOT ac DOT jp (Colin Peters)
Subject: RE: scanf "%n" format specifier is not supported
24 Jun 1998 09:57:52 -0700 :
Message-ID: <003201bd9f13$fab1e740$fa173185.cygnus.gnu-win32@gbird0.fu.is.saga-u.ac.jp>
Mime-Version: 1.0
To: "Alexander Chernov" <cher AT ispras DOT ru>
Cc: "GNU-Win32" <gnu-win32 AT cygnus DOT com>

Alexander Chernov <cher AT ispras DOT ru> wrote:

>On Tue, 23 Jun 1998, Colin Peters wrote:
>> Aside from the typo above the reason the code doesn't work is that sscanf
>> never gets as far as the %n. It stops when it reaches the end of the
string
>> "32" while looking for a whitespace to match the space between %d and %n.
>> Try adding a space to the end of "32" like this:
>>
>> r = sscanf("32 ", "%d %n", &v, &n);
>
>Ok, but atleast on Linux, HPUX and Solaris sscanf works as described
>above,
>ie "r = sscanf("32", "%d %n", &v, &n);" sets r to 1, v to 32 and n to 2.
>I looked at my C book, and It says nothing on this topic, though...


Actually, on closer reading of the appendix in my copy of K&R it appears
that you (and Linux, etc.) are right. Blanks or tabs in the format string
are supposed to be *ignored*. Of course this is a pretty odd case. I suppose
the people at MS (and Cygnus, since they seem to have the same problem)
thought the way I did, that white space in the format string is supposed to
match white space in the input.

Of course all this is based on K&R being correct (it is the 2nd, ANSI C,
edition). I'm not sure what the standard itself says.

In any case it's probably safer to do it some other way, as you said.

Apologies for the waste of bandwidth,
Colin.

-- Colin Peters - colin at fu.is.saga-u.ac.jp
-- Saga Univ. Dept. of Information Science
-- http://www.geocities.com/Tokyo/Towers/6162/index.html
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


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