Name
vfprintf, vprintf, vsnprintf, vsprintf
Synopsis
Writes formatted output using a variable argument list object
#include <stdio.h> #include <stdarg.h> intvfprintf( FILE * restrictfp, const char * restrictformat, va_listargptr); intvprintf( const char * restrictformat, va_listargptr); intvsprintf( char * restrictbuffer, const char * restrictformat, va_listargptr); intvsnprintf( char * restrictbuffer, size_tn, const char * restrictformat, va_listargptr); (C99)
The functions vfprintf(),
vprintf(), vsprintf(), and vsnprintf() work in the same way as
fprintf(), printf(), sprintf(), and snprintf(), respectively, except that
their last 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 vfprintf(), vprintf(), vsprintf(), or vsnprintf() function, and must call the
va_end() macro after the function
returns. Because these functions use the va_arg() macro internally to advance
argptr through the argument list, its
value is indeterminate after the vfprintf(), vprintf(), vsprintf(), or vsnprintf() 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 fprintf() and
printf() functions, vfprintf() and vprintf(), return the number of characters
written to the output stream. The function vsprintf() returns the number of characters written to the string buffer, not counting the terminator ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access