scanf %x allows leading 0x?!?

Peter da Silva peter at ficc.ferranti.com
Tue May 14 09:16:09 AEST 1991


In article <725 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
> scjones at thor.sdrc.com (Larry Jones) writes:
> |I was just surprised to discover that the %x conversion specifier
> |used in the *scanf functions allows the target string to have a
> |leading 0x or 0X.

> It is the explicitly-specified behavior in ANSI C.  On systems which
> do not follow the ANSI standard, you may get different behavior.

OK, whose bright idea was this? I know scanf is pretty much a loss in general,
but doesn't this further dilute its reliability?

Given:
	scanf("%x%c", &integer, &byte);

With the input
	4300ay
	0 b
	0cx
	0x

Is this supposed to fail on the final example, or succeed?
-- 
Peter da Silva; Ferranti International Controls Corporation; +1 713 274 5180;
Sugar Land, TX  77487-5012;         `-_-' "Have you hugged your wolf, today?"



More information about the Comp.std.c mailing list