Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-157
scanf
scanf
The scanf function reads formatted data from the standard input file, uses the format
string to determine whether the data matches expectations and to determine the
necessary conversions, and writes converted data to one or more supplied variables.
format
points to a string that specifies how to convert the input text for assignment, using
subsequent arguments as pointers to the variables that receive the converted input.
Refer to “fscanf” on page 3-61 for a description of format.
obj_ptr...
is a list of pointers to variables, specifying where the results of the conversions
defined in *format are to be stored.
Return Value
is the number of items for which scanf found valid data, including all single-
character items in *format that were matched. If an error occurs, scanf returns the
value EOF.
Usage Guidelines
The conversion specifiers must agree in number and type with the pointers in
obj_ptr....
If you use the suppression feature (*), do not supply a pointer for that specifier.
Example
This example reads a number from the standard input file, converts it to a long floating-
point number, and places it in variable x:
#include <stdioh>
double r;
double x;
scanf("%f", &x);
r = sqrt(x);
printf ("The square root of %f is %f", x, r);
#include <stdioh>
int scanf(const char *format, [obj_ptr...]);