HP C/iX Library Reference Manual (30026-90004)

296 Chapter5
HP C/iX Library Function Descriptions
scanf
scanf
Reads externally formatted data from the standard input stream stdin.
Syntax
#include <stdio.h>
int scanf (const char *
format [,item [,item]...]
);
Parameters
format
A pointer to a character string defining the format of the data to be read
(or the character string itself enclosed in double quotes).
item
Each
item
is the address of a variable into which the data will be placed.
Return Values
0 The number of successfully matched and assigned input items.
EOF An error occurred on input (no input characters, or a matching error
occurred before any conversion).
Description
The scanf function reads externally formatted data from the standard input stream
stdin, converts the data to internal format, and stores the results in a string of
arguments.
In the scanf function,
format
is a character pointer to a character string (or the character
string itself enclosed in double quotes), and
item
is the address of a variable. The scanf
function returns the number of successfully matched and assigned input items or returns
EOF if there are no input characters available or if a matching error occurred before any
conversion was made.
The purpose of the format is to specify how the data to be read is presented on stdin and
what types of data are found there. The format consists of white-space characters,
conversion specifications, and literal characters.
White-Space Characters
White-space characters (blanks, tabs, newlines, or form feeds) cause input to be read up to
the next non-white-space character.
Conversion Specifications
A conversion specification is a character sequence that tells scanf() how to interpret the
data received at that point in the input.
In the format, a conversion specification is introduced by a percent sign (%), optionally
followed by an asterisk (*) (called the assignment suppression character), optionally