![]() |
![]() |
![]() |
![]() |
Scan input from a file
#include <stdio.h> #include <stdarg.h> int vfscanf( FILE *fp, const char *format, va_list arg );
libc
The vfscanf() function scans input from the file designated by fp, under control of the argument format. For information about the format string, see the description of scanf().
The vfscanf() function is equivalent to fscanf(), with a variable argument list replaced with arg, which has been initialized using the va_start() macro.
EOF when the scanning is stopped by reaching the end of the input stream before storing any values, or the number of input arguments for which values were successfully scanned and stored.
If an error occurs, errno indicates the type of error.
#include <stdio.h> #include <stdlib.h> #include <stdarg.h> void ffind( FILE *fp, char *format, ... ) { va_list arglist; va_start( arglist, format ); vfscanf( fp, format, arglist ); va_end( arglist ); } int main( void ) { int day, year; char weekday[10], month[12]; ffind( stdin, "%s %s %d %d", weekday, month, &day, &year ); printf( "\n%s, %s %d, %d\n", weekday, month, day, year ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
errno, fscanf(), scanf(), sscanf(), va_arg(), va_end(), va_start(), vsscanf()
![]() |
![]() |
![]() |
![]() |