vprintf(3S) UNIX System V(C Development Set) 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, valist ap);
int vfprintf(FILE *stream, const char *format, valist ap);
int vsprintf(char *s, const char *format, valist 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 valist 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 valist.
This argument is used with the stdarg.h header file macros vastart,
vaarg and vaend [see vastart, vaarg, and vaend 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(functionname, format, arg1, . . .);
*/
void error(char *functionname, char *format, . . .)
{
valist ap;
vastart(ap, format);
/* print out name of function causing error */
(void) fprintf(stderr, "ERR in %s: ", functionname);
vaarg(ap, char*);
/* print out remainder of message */
(void) vfprintf(stderr, format, ap);
vaend(ap);
(void) abort;
}
SEE ALSO
printf(3S), stdarg(5)
10/89 Page 1
vprintf(3S) UNIX System V(C Development Set) vprintf(3S)
DIAGNOSTICS
vprintf and vfprintf return the number of characters transmitted, or
return -1 if an error was encountered.
Page 2 10/89