scanf.3s (2010 09)
s
scanf(3S) scanf(3S)
NAME
scanf(), fscanf(), sscanf() - formatted input conversion, read from stream file
SYNOPSIS
#include <stdio.h>
int scanf(const char *__restrict format, /* [pointer,] */ ...);
int fscanf(FILE *__restrict stream, const char *__restrict format, /*
[pointer,] */ ...);
int sscanf(const char *__restrict s, const char *__restrict 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 h, hh,
j, l (ell), L, ll (ell
ell),
t,orz indicating the size of the receiving variable and a conversion code.
• For Itanium(R)-based systems if the optional decimal floating point feature is installed and
enabled, the following optional character specifications are allowed:
An optional
H specifying that a following f, F, e, E, g
, G, a,orA conversion specifier applies to
an argument with type pointer to
_Decimal32.
An optional
D specifying that a following f, F, e, E, g
, G, a,orA conversion specifier applies to
an argument with type pointer to
_Decimal64.
An optional
DD specifying that a following f, F, e, E, g,
G, a,orA conversion specifier applies to
an argument with type pointer to
_Decimal128.
The behavior of the
f, F, e, E, g, G, a
,orA conversion specifiers for decimal floating point
numbers is the same as for double except hexadecimal floating-point input is not accepted.
• 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.
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1