Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.std.c Subject: Re: sscanf sequential assignment? Message-ID: <734@taumet.com> Date: 17 May 91 15:52:22 GMT References: <4325@rwthinf.UUCP> Organization: Taumetric Corporation, San Diego Lines: 28 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