scanf.3s (2010 09)

s
scanf(3S) scanf(3S)
int i, n1, n2, n3, n4;
n1=n2=n3=n4=-1;
scanf("%nBEGIN%n %d %nEND%n", &n1, &n2, &i, &n3, &n4);
if (n2 - n1 == 5) puts( "matched BEGIN");
if (n4 - n3 == 3) puts( "matched END");
Here is an example that checks the success of suppressed assignments:
int i, n1, n2;
n1=n2=-1;
scanf( "%d %n%*s%n", &i, &n1, &n2);
if (n2 > n1)
printf("successful assignment suppression of %d chars\n", n2-n1);
APPLICATION USAGE
After
scanf() or fscanf() is applied to a stream, the stream becomes byte-oriented (see orienta-
tion (5)).
WARNINGS
Trailing white space (including a newline) is left unread unless matched in the control string.
Truncation of multi-byte characters may occur if a field width is used with the conversion character.
AUTHOR
scanf() was developed by AT&T and HP.
SEE ALSO
getc(3S), printf(3S), setlocale(3C), strtod(3C), strtol(3C), orientation(5), thread_safety(5), glossary(9).
STANDARDS CONFORMANCE
scanf(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
fscanf(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
sscanf(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
HP-UX 11i Version 3: September 2010 5 Hewlett-Packard Company 5