[comp.std.c] Another scanf interpretation question

chris@mimsy.umd.edu (Chris Torek) (01/04/90)

The December 1988 draft standard indicates that for %[dioux] scanf
conversions (and their |long| and suppressed-assignment variants),
the format of the number is to match that accepted by strtol or
strtoul.  This is all well and good, except that strtol and strtoul
are defined such that they `accept' numbers of the form

	+

and

	-

(which both convert to the value 0).  This is reasonable for strtol
and strtoul, but perhaps not so for scanf.

The question, then, can be expressed this way:

  Should  sscanf("+", "%d", &i)  convert one integer, putting 0 in `i'?
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris

chris@mimsy.umd.edu (Chris Torek) (01/05/90)

In article <21624@mimsy.umd.edu> I wrote:
>... strtol and strtoul are defined such that they `accept' numbers
>[consisting of only a sign]

Oops: although they return zero, they do not consume the sign, so that
given `strtol("-", &endptr, 0)', *endptr will be '-'.  In effect, they
do not accept numbers consisting of only a sign.

(In other words, the floating point question applies.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris

gwyn@smoke.BRL.MIL (Doug Gwyn) (01/05/90)

In article <21624@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes:
-... strtol and strtoul
- are defined such that they `accept' numbers of the form
-	+
-and
-	-
-(which both convert to the value 0).  ...

No, I don't think so.  A subset of the "expected form" of the subject
sequence is an integer constant according to the rules of 3.1.3.2, and
empty strings do not qualify as valid integer constants.