scan input from a file
#include <stdio.h> int fscanf( FILE *fp, const char *format, ... );
The fscanf() function scans input from the file designated by fp, under control of the argument format. Following the format string is a list of addresses to receive values. The format string is described under the description of the scanf() function.
The number of input arguments for which values were successfully scanned and stored, or EOF when the scanning is terminated by reaching the end of the input stream. When a file input error occurs, errno may be set.
To scan a date in the form "Saturday April 18 1987":
#include <stdio.h> void main() { int day, year; char weekday[10], month[10]; FILE *in_data; in_data = fopen( "file", "r" ); if( in_data != NULL ) { fscanf( in_data, "%s %s %d %d", weekday, month, &day, &year ); printf( "Weekday=%s Month=%s Day=%d Year=%d\n", weekday, month, day, year ); fclose( in_data ); } }
ANSI
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
cscanf(), errno, scanf(), sscanf(), vcscanf(), vfscanf(), vscanf(), vsscanf()