HP-UX Reference (11i v1 05/09) - 3 Library Functions N-Z (vol 7)
s
scanf(3S) scanf(3S)
n Cause the total number of bytes (including white space) scanned since the function call to
be stored; the corresponding argument should be an integer pointer. No input is con-
sumed. The function return value does not include
%n assignments in the count of suc-
cessfully matched and assigned input items.
e,E,f,g,G
A floating-point number is expected; the next field is converted accordingly and stored
through the corresponding argument, which should be a pointer to a float. The input for-
mat for floating-point numbers is an optionally signed string of digits, possibly containing
a radix character, followed by an optional exponent field consisting of an
E or an e, fol-
lowed by an optional
+, -
, or space, followed by an integer. The conversion characters E
and G behave the same as, respectively,
e and g. The e
, E, f, g, and G conversions will
convert the string
inf (case insensitive) or the string
infinity (case insensitive) to
the appropriate floating point infinity value (single, double, or quadruple precision, as
specified by the conversion precision modifier). The
e, E, f, g, and G conversions will
convert the string
nan (case insensitive) to the appropriate floating point
NaN value (sin-
gle, double, or quadruple precision, as specified by the conversion precision modifier).
c A character is expected; the corresponding argument should be a character pointer. The
normal skip-over-white-space is suppressed in this case; to read the next non-space char-
acter, use
%1s. If a field width is given, the corresponding argument refers to a charac-
ter array; the indicated number of characters is read.
If an l (ell) qualifier is present, the input is a sequence of characters that begins in the
initial shift state. Each character in the sequence is converted to a wide-character as if
by a call to the mbrtowc() function, with the conversion state described by an
mbstate_t object initialized to zero before the first character is converted. The
corresponding argument must be a pointer to an array of wchar_t large enough to
accept the resulting sequence of wide-characters. No null wide-character is added. The
normal skip-over-white-space is suppressed in this case; to read the next non-space char-
acter, use %1S. If a field width is given, the corresponding argument refers to a wide
character array; the indicated number of characters is read and converted.
C Same as lc.
s A character string is expected; the corresponding argument should be a character pointer
pointing to an array of characters large enough to accept the string and a terminating
\0, which is added automatically. The input field is terminated by a white-space charac-
ter. scanf() cannot read a null string.
If an l (ell) qualifier is present, the input is a sequence of characters that begins in the
initial shift state. Each character is converted to a wide-character as if by a call to the
mbrtowc() function, with the conversion state described by an mbstate_t object
initialized to zero before the first character is converted. The corresponding argument
must be a pointer to an array of wchar_t large enough to accept the sequence and the
terminating null wide-character, which will be added automatically. The input field is
terminated by a white-space character. scanf() cannot read a null string.
S Same as ls.
[ Indicates string data and the normal skip-over-leading-white-space is suppressed. The
left bracket is followed by a set of characters, called the scanset, and a right bracket; the
input field is the maximal sequence of input characters consisting entirely of characters
in the scanset. The circumflex (ˆ), when it appears as the first character in the scanset,
serves as a complement operator and redefines the scanset as the set of all characters not
contained in the remainder of the scanset string. Construction of the scanset follows cer-
tain conventions. A range of characters may be represented by the construct first-last,
enabling [0123456789]to be expressed [0-9]. Using this convention, first must be lexically
less than or equal to last; otherwise, the dash stands for itself. The dash also stands for
itself when it is the first or the last character in the scanset. To include the right square
bracket as an element of the scanset, it must appear as the first character (possibly pre-
ceded by a circumflex) of the scanset, in which case it will not be interpreted syntactically
as the closing bracket. The corresponding argument must point to a character array
large enough to hold the data field and the terminating \0, which are added automati-
cally. At least one character must match for this conversion to succeed.
If an l (ell) qualifier is present, the input is a sequence of characters that begins in the
initial shift state. Each character in the sequence is converted to a wide-character as if
HP-UX 11i Version 1: September 2005 − 2 − Hewlett-Packard Company Section 3−−859