VPRINTF(3S)VPRINTF(3S)NAME
vprintf, vfprintf, vsnprintf, vsprintf - print formatted output of a
variable argument list
SYNOPSIS
#include <stdarg.h>
#include <stdio.h>
int vprintf (const char *format, va_list arg);
int vfprintf (FILE *stream, const char *format, va_list arg);
int vsnprintf (char *s, size_t len, const char *format, va_list arg);
int vsprintf (char *s, const char *format, va_list arg);
DESCRIPTION
vprintf, vfprintf, vsnprintf, and vsprintf are the same as printf,
fprintf, snprintf, and sprintf respectively, except that instead of being
called with a variable number of arguments, they are called with an
argument list, arg, as defined by stdarg(5). The arg parameter must be
initialized by the va_start macro (and possibly subsequent va_arg calls).
The vprintf, vfprintf, vsnprintf, and vsprintf functions do not invoke
the va_end macro.
EXAMPLE
The following demonstrates the use of vfprintf to write an error routine.
The stdarg.h header file defines the type va_list and a set of macros for
advancing through a list of arguments whose number and types may vary.
The argument ap to the vprint family of routines is of type va_list.
This argument is used with the stdarg.h header file macros va_start,
va_arg and va_end [see va_start, va_arg, and va_end in stdarg(5)].
#include <stdio.h>
#include <stdarg.h>
/*
* error should be called as:
* error(function_name, format, arg1, arg2 ...);
*/
void
error(char *function_name, char *format, ...)
{
va_list args;
va_start(args, format);
/* print out name of function causing error */
fprintf(stderr, "ERROR in %s: ", function_name);
/* print out remainder of message */
vfprintf(stderr, format, args);
va_end(args);
Page 1
VPRINTF(3S)VPRINTF(3S)
}
SEE ALSOprintf(3S), stdarg(5).
DIAGNOSTICS
vprintf, vfprintf, vsnprintf, and vsprintf return the number of
characters transmitted, or return -1 if an error was encountered.
Page 2