HP-UX Reference (11i v2 03/08) - 3 Library Functions N-Z (vol 7)
s
scanf(3S) scanf(3S)
NAME
scanf, fscanf, sscanf - formatted input conversion, read from stream file
SYNOPSIS
#include <stdio.h>
int scanf(const char *format, /* [pointer,] */ ...);
int fscanf(FILE *stream, const char *format, /* [pointer,] */ ...);
int sscanf(const char *s, const char *format, /* [pointer,] */ ...);
DESCRIPTION
scanf() reads from the standard input stream stdin.
fscanf() reads from the named input stream .
sscanf() reads from the character string s.
Each function reads characters, interprets them according to the control string format argument, and
stores the results in its pointer arguments. If there are insufficient arguments for the format, the
behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are
ignored. The control string contains conversion specifications and other characters used to direct
interpretation of input sequences. The control string contains:
• White-space characters (blanks, tabs, newlines, or formfeeds) that cause input to be read up to
the next non-white-space character (except in two cases described below).
• An ordinary character (not
%) that must match the next character of the input stream.
• Conversion specifications, consisting of the character
%, an optional assignment suppressing
character *, an optional numerical maximum-field width, an optional l (ell), ll, (ell ell),
h or
L indicating the size of the receiving variable, and a conversion code.
• The conversion specification can alternatively be prefixed by the character sequence
%n$ instead
of the character
%, where n is a decimal integer in the range (1 − {NL_ARGMAX}
)(NL_ARGMAX
is defined in <limits.h>). The %n$ construction indicates that the value of the next input
field should be placed in the nth argument, rather than to the next unused one. The two forms
of introducing a conversion specification, % and %n$, must not be mixed within a single format
string with the following exception: Skip fields (see below) can be designated as
%* or
%n$*. In
the latter case, n is ignored.
Unless the specification contains the
n conversion character (described below), a conversion specification
directs the conversion of the next input field. The result of a conversion specification is placed in the vari-
able to which the corresponding argument points, unless
* indicates assignment suppression. Assign-
ment suppression provides a way to describe an input field to be skipped. An input field is defined as a
string of non-space characters; it extends to the next inappropriate character or until the field width, if
specified, is exhausted. For all descriptors except
[ and c, white space leading an input field is ignored.
The conversion code indicates the interpretation of the input field; the corresponding pointer argument
must be of a restricted type. For a suppressed field, no pointer argument is given. The following conver-
sion codes are legal:
% A single % is expected in the input at this point; no assignment is done.
d A decimal integer is expected; the corresponding argument should be an integer
pointer.
u An unsigned decimal integer is expected; the corresponding argument should be an
unsigned integer pointer.
o An octal integer is expected; the corresponding argument should be an unsigned
integer pointer.
x, X A hexadecimal integer is expected; the corresponding argument should be an unsigned
integer pointer. The x and X conversion characters are equivalent.
i An integer is expected; the corresponding argument should be an integer pointer. The
value of the next input item, interpreted according to C conventions, will be stored; a
leading 0 implies octal, a leading 0x implies hexadecimal; otherwise, decimal is
assumed.
HP-UX 11i Version 2: August 2003 − 1 − Hewlett-Packard Company Section 3−−923