sscanf sequential assignment?
Stephen Clamage
steve at taumet.com
Sat May 18 01:52:22 AEST 1991
berg at marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) writes:
>Does the Standard say anything about a guaranteed assignment sequence
>for sscanf?
>i.e.: char *str,*p,dest[80];
> sscanf(str," %n%s %n",&p,dest,&p);
>Will p guaranteed to get it's value from the second '%n' if 'str'
>doesn't point to an empty or all whitespace string?
Your code is incorrect, so lets fix it first. The argument corresponding
to the %n must be of type int*, but yours is type char**. Try this:
char *str, dest[80];
int p;
sscanf(str, " %n%s %n", &p, dest, &p);
The Standard requires that scanf execute each directive in turn, so
if str is ok, p must get the value of the second %n.
>Since we're at it anyway, what about backward portability with older
>libraries, do all old libs support the '%n' identifier too?
No, not all older libraries support %n. Some libraries support %n but
not %hn, where the corresponding argument points to a short.
--
Steve Clamage, TauMetric Corp, steve at taumet.com
More information about the Comp.std.c
mailing list