.\" @(#)scanf.3 6.2 (Berkeley) 4/1/89
.TH SCANF 3 "April 1, 1989"
scanf, fscanf, sscanf \- formatted input conversion
reads from the standard input stream
reads from the named input
reads from the character string
Each function reads characters, interprets
them according to a format, and stores the results in its arguments.
Each expects as arguments
indicating where the converted input should be stored.
conversion specifications, which are used to direct interpretation
The control string may contain:
Blanks, tabs or newlines,
which match optional white space in the input.
An ordinary character (not %) which must match
the next character of the input stream.
Conversion specifications, consisting of the
an optional assignment suppressing character
an optional numerical maximum field width, and a conversion
A conversion specification directs the conversion of the
next input field; the result
is placed in the variable pointed to by the corresponding argument,
unless assignment suppression was
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.
The conversion character indicates the interpretation of the
input field; the corresponding pointer argument must
usually be of a restricted type.
The following conversion characters are legal:
in the input at this point;
a decimal integer is expected;
the corresponding argument should be an integer pointer.
an octal integer is expected;
the corresponding argument should be a integer pointer.
a hexadecimal integer is expected;
the corresponding argument should be an integer pointer.
a character string is expected;
the corresponding argument should be a character pointer
pointing to an array of characters large enough to accept the
string and a terminating `\e0', which will be added.
The input field is terminated by a space character
a character is expected; the
corresponding argument should be a character pointer.
The normal skip over space characters is suppressed
to read the next non-space character, try
If a field width is given, the corresponding argument
should refer to a character array, and the
indicated number of characters is read.
floating point number is expected;
the next field is converted accordingly and stored through the
corresponding argument, which should be a pointer to a
floating point numbers is
possibly containing a decimal point, followed by an optional
exponent field consisting of an E or e followed by an optionally signed integer.
indicates a string not to be delimited by space characters.
The left bracket is followed by a set of characters and a right
bracket; the characters between the brackets define a set
of characters making up the string.
is not circumflex (\|^\|), the input field
is all characters until the first character not in the set between
the brackets; if the first character
after the left bracket is ^, the input field is all characters
until the first character which is in the remaining set of characters
The corresponding argument must point to a character array.
The conversion characters
may be capitalized or preceded by
to indicate that a pointer to
Similarly, the conversion characters
The conversion characters
functions return the number of successfully matched and assigned input
This can be used to decide how many input items were found.
is returned upon end of input; note that this is different
from 0, which means that no conversion was done;
if conversion was intended, it was frustrated by an
inappropriate character in the input.
int i; float x; char name[50];
scanf("%d%f%s", &i, &x, name);
int i; float x; char name[50];
scanf("%2d%f%*d%[1234567890]", &i, &x, name);
and place the string `56\e0' in
and a short count for missing or illegal data items.
The success of literal matches and suppressed
assignments is not directly