berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) (05/17/91)
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? Since we're at it anyway, what about backward portability with older libraries, do all old libs support the '%n' identifier too? -- Sincerely, berg@marvin.e17.physik.tu-muenchen.de Stephen R. van den Berg. "I code it in 5 min, optimize it in 90 min, because it's so well optimized: it runs in only 5 min. Actually, most of the time I optimize programs."
steve@taumet.com (Stephen Clamage) (05/17/91)
berg@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@taumet.com