Name
vfscanf, vscanf, vsscanf
Synopsis
Reads formatted data using a variable argument list
#include <stdio.h> #include <stdarg.h> intvfscanf
( FILE * restrictfp
, const char * restrictformat
, va_listargptr
); intvscanf
( const char * restrictformat
, va_listargptr
); intvsscanf
( char * restrictbuffer
, const char * restrictformat
, va_listargptr
);
The functions vfscanf()
,
vscanf()
, and vsscanf()
work in the same way as fscanf()
, scanf()
, and sscanf()
, respectively, except that their
final argument, argptr
, is a
variable-argument list object with type va_list
. The program must initialize this
object by calling the va_start
macro before calling the vfscanf()
, vscanf()
, or vsscanf()
function, and must call the
va_end()
macro after the function
returns. Because these functions use the va_arg()
macro internally to advance the
pointer through the argument list, its value is indeterminate after
the vfscanf()
, vscanf()
, or vsscanf()
function call has
returned.
Tip
The va_start()
, va_arg()
, and va_end()
macros and the type va_list
are declared in the header file
stdarg.h.
Like the fscanf()
, scanf()
, and sscanf()
functions, vfscanf()
, vscanf()
, and vsscanf()
return the number of input items
that have been assigned to variables referenced by elements of the
argument list.
Example
typedef struct { char lastname[20]; char firstname[20]; int dob_month; int dob_day; int dob_year; } person; person employee; int read_person( char *lname, char *fname, ... ) // As variable arguments (...) use NULL // ...
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.