HP-UX Reference (11i v3 07/02) - 3 Library Functions N-Z (vol 7)
s
scanf(3S) scanf(3S)
certain 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
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.
p A sequence of unsigned hexadecimal numbers is expected. This sequence may be pro-
duced by the
p conversion character of printf(). The corresponding argument shall
be a pointer to a pointer to void into which the value represented by the hexadecimal
sequence is stored. The behavior of this conversion is undefined for any input item other
than a value converted earlier during the same program execution.
The conversion characters d, i, and n can be preceded by h, hh,
j, l, ll, t,orz to indicate that a
pointer to a
short int, signed char, intmax_t, long int, long long int
, ptrdiff_t,
or
ssize_t rather than to an int is in the argument list. Similarly, the conversion characters
u, o, x,
and
X can be preceded by h, hh, j, l, ll, t
,orz to indicate that a pointer to a unsigned short
int
, unsigned char, uintmax_t , unsigned long int, unsigned long long int,
unsigned ptrdiff_t,orsize_t rather than to an unsigned int is in the argument list.
Finally, the conversion characters e, E, f, F, g, and G can be preceded by
l or L to indicate that a pointer
to a
double or long double rather than to a float is in the argument list. The
h, hh, j, l, L, ll,
t,orz modifier is ignored for other conversion characters.
The scanf() functions terminate their conversions at EOF, at the end of the control string, or when an
input character conflicts with the control string. In the latter case, the offending character is left unread in
the input stream.
EXTERNAL INFLUENCES
Locale
The LC_CTYPE category determines the interpretation of ordinary characters within format strings as sin-
gle and/or multi-byte characters. Field width is given in terms of bytes. Characters received from the
input stream are interpreted as single- or multi-byte characters as determined by the LC_TYPE category
and the field width is decremented by the length of the character.
The
LC_NUMERIC category determines the radix character expected within floating-point numbers.
International Code Set Support
Single- and multi-byte character code sets are supported.
RETURN VALUE
If the input ends before the first conflict or conversion, EOF is returned. Otherwise, these functions return
the number of successfully assigned input items. This number is a short count, or even zero if a conflict
ensues between an input character and the control string.
ERRORS
scanf() and fscanf() fail if data needs to be read into the stream’s buffer, and:
[EAGAIN] The O_NONBLOCK flag is set for the file descriptor underlying stream and the pro-
cess would be delayed in the read operation.
[EBADF] The file descriptor underlying stream is not a valid file descriptor open for reading.
[EINTR] The read operation was terminated due to the receipt of a signal, and either no data
was transferred or the implementation does not report partial transfer for this file.
372 Hewlett-Packard Company − 3 − HP-UX 11i Version 3: February 2007