fscanf
Scans and formats input from a stream.
Defined in header <stdio.h>
Syntax
#include <stdio.h>
int fscanf(FILE *stream, const char *format[, address, ...]);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
fscanf scans a series of input fields, one character at a time, reading from a stream. Then each field is formatted according to a format specifier passed
See scant for details
to fscanf in the format string pointed to by format. Finally, fscanf stores
on format specifiers.
^^^ formatted input at an address passed to it as an argument following format. The number of format specifiers and addresses must be the same as the number of input fields.
fscanf can stop scanning a particular field before it reaches the normal end-of-field character (whitespace), or it can terminate entirely for a number of reasons. See scanf for a discussion of possible causes.
Return value
fscanf returns the number of input fields successfully scanned, converted, and stored; the return value does not include scanned fields that were not stored.
If fscanf attempts to read at end-of-file, the return value is EOF. If no fields were stored, the return value is 0.
See also
Example
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int i;
printf("Input an integer: ");
/* read an integer from the standard input stream */
if (fscanf(stdin, "%d", &i))
printfC'The integer read was: %i\n", i);
else {
fprintf(stderr, "Error reading an integer from stdin.\n"),•
exit(l);
}
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdio.h/fscanf/
· short form /3.1/fscanf/