C examples for stdio.h:vfscanf
function
<cstdio> <stdio.h>
Read formatted data from stream into variable argument list
int vfscanf ( FILE * stream, const char * format, va_list arg );
Parameter | Description |
---|---|
stream | FILE object. |
format | format string |
arg | a variable arguments list initialized with va_start. |
On success, the function returns the number of items filled.
#include <stdio.h> #include <stdarg.h> void ReadStuff (FILE * stream, const char * format, ...) { va_list args;// w ww.j ava 2s . co m va_start (args, format); vfscanf (stream, format, args); va_end (args); } int main () { FILE * pFile; int val; char str[100]; pFile = fopen ("main.cpp","r"); if (pFile ==NULL) { printf("error"); return -1; } ReadStuff ( pFile, " %s %d ", str, &val ); printf ("I have read %s and %d", str, val); fclose (pFile); return 0; }