Reads input from a character string in memory, interpreting it according to the format specification.
#include <stdio.h> int sscanf (const char *str, const char *format_spec, . . . );
If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have at least as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers.
Conversion specifications are matched to input sources in left-to- right order. Excess input pointers, if any, are ignored.
main () { char str[] = "4 17"; int temp, temp2; sscanf(str, "%d %d", &temp, &temp2); printf("The answers are %d and %d.", temp, temp2); }
This example produces the following output:
$ RUN EXAMPLE The answers are 4 and 17.
For a complete description of the format specification and the input pointers, see Chapter 2.
x | The number of successfully matched and assigned input items. |
EOF | Indicates that a read error occurred before any conversion.The function sets errno. For a list of the values set by this function, see fscanf in this section. |