bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sscanf broken?


From: Andreas Jaeger
Subject: Re: sscanf broken?
Date: Wed, 12 Sep 2001 13:47:22 +0200
User-agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.4 (Artificial Intelligence)

matt farnsworth <address@hidden> writes:

> I expected 'sscanf(src,form,*to...)' to parse like a weak regex; but it
> doesn't!
>
> consider
>  sscanf("URL http://svr.any.srv mode/1.1\n", 
>       "URL http://%s mode/%d.%d", 
>       &host, &maj, &min); == 3 // ok
> but 
>  sscanf("URL http://svr.any.srv/resource mode/1.1\n", 
>       "URL http://%s/%s mode/%d.%d", 
>       &host, &res, &maj, &min); == 1 // FAIL
> and 
>    sscanf("URL http://svr.any.srv /resource mode/1.1\n", 
>       "URL http://%s /%s mode/%d.%d", 
>       &host, &res, &maj, &min); == 4 // ok, but wrong params
>
> thus shown
>    sscanf requires %s to terminate with a <space>
> but I expected
>    %s<non-s-char> ==> {break on non-s-char}
> as in
>    when 'scan'ing for end of %s the first occurance of <char-after-%s>
> terminates %s
> thus 
>    '/' was the intended delimiter, but sscanf walked until the first
> space 
>     eg. $1=//svr.any.srv/resource
>
> Is this really standard behaviour?  Does this suck?

If you want a regex, use one.

The ISO C standard specifies that "%s" matches " Matches a sequence of
non-white-space characters", glibc is correct,

Andreas
-- 
 Andreas Jaeger
  SuSE Labs address@hidden
   private address@hidden
    http://www.suse.de/~aj



reply via email to

[Prev in Thread] Current Thread [Next in Thread]