HP-UX Reference (11i v2 04/09) - 3 Library Functions N-Z (vol 7)

s
scanf(3S) scanf(3S)
construct first-last, enabling [0123456789] to be expressed [0-9]. Using this conven-
tion, 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 preceded 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 automatically. 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 hexa-
decimal 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 l, ll or
h to indicate that a pointer to a long
int, long long int or short int rather than to an int is in the argument list. Similarly, the
conversion characters u, o, x, and X can be preceded by l,
ll or h to indicate that a pointer to
unsigned long int, unsigned long long int,orunsigned short int rather than to an
unsigned int, is in the argument list. Finally, the conversion characters e, E,
f, g, and G can be pre-
ceded 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
l, ll, L or h 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
single 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.
[EIO] The process is a member of a background process and is attempting to read from its
controlling terminal, and either the process is ignoring or blocking the SIGTTIN
signal or the process group of the process is orphaned.
Section 3944 Hewlett-Packard Company 3 HP-UX 11i Version 2: September 2004