HP-UX Reference (11i v1 05/09) - 3 Library Functions N-Z (vol 7)
s
scanf(3S) scanf(3S)
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 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 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 VALUES
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 process
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 sig-
nal or the process group of the process is orphaned.
[EILSEQ] The data obtained from the input stream does not form a valid wide character.
Additional errno values can be set by the underlying read() function (see read(2)).
EXAMPLES
The call:
int i, n; float x; char name[50];
n = scanf("%d%f%s", &i, &x, name);
with the input line:
Section 3−−860 Hewlett-Packard Company − 3 − HP-UX 11i Version 1: September 2005