vprintf(3S) STANDARD I/O FUNCTIONS vprintf(3S)
NAME
vprintf, vfprintf, vsprintf - print formatted output of a
variable argument list
SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vsprintf(char *s, const char *format, va_list ap);
DESCRIPTION
vprintf, vfprintf and vsprintf are the same as printf,
fprintf, and sprintf respectively, except that instead of
being called with a variable number of arguments, they are
called with an argument list as defined by the <stdarg.h>
header file.
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)]. The EXAMPLE section below shows their use with
vprintf.
EXAMPLE
The following demonstrates how vfprintf could be used to
write an error routine:
#include <stdio.h>
#include <stdarg.h>
/*
* error should be called like
* error(function_name, format, arg1, ...);
*/
void error(char *function_name, char *format, ...)
{
va_list ap;
va_start(ap, format);
/* print out name of function causing error */
(void) fprintf(stderr, "ERR in %s: ", function_name);
va_arg(ap, char*);
/* print out remainder of message */
(void) vfprintf(stderr, format, ap);
va_end(ap);
(void) abort;
}
Last change: C Programming Language Utilities 1
vprintf(3S) STANDARD I/O FUNCTIONS vprintf(3S)
SEE ALSO
printf(3S), stdarg(5).
DIAGNOSTICS
vprintf and vfprintf return the number of characters
transmitted, or return -1 if an error was encountered.
Last change: C Programming Language Utilities 2