Format
#include <stdarg.h> #include <stdio.h> int vprintf(const char *format, va_list arg_ptr);
Language Level: ANSI, XPG4, Extension
vprintf formats and prints a series of characters and values to
stdout. vprintf works just like printf, except that arg_ptr
points to a list of arguments whose number can vary from call to
call in the program. These arguments should be initialized by
va_start for each call. In contrast, printf can have a list of
arguments, but the number of arguments in that list is fixed when
you compile the program.
vprintf converts each entry in the argument list according to the corresponding format specifier in format. The format has the same form and function as the format string for printf. For a description of the format string, see printf -- Print Formatted Characters.
In extended mode, vprintf also converts floating-point values of NaN and infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case and sign of the string is determined by the format specifiers.
If you specify a null string, on OS/2 and Windows, for the %s or %ls format specifier, vfprintf prints (null). (In previous releases of the C/C++ run-time library, vprintf produced no output for a null string.)
Return Value
If successful, vprintf returns the number of bytes
written to stdout. If an error occurs, vprintf returns a negative
value.
Example
This example prints out a variable number of strings to
stdout.
#include <stdarg.h> #include <stdio.h>
#define FILENAME "myfile.dat"
void vout(char *fmt, ...);
char fmt1 [] = "%s %s %s %s %s \n";
int main(void)
{
FILE *stream;
stream = fopen(FILENAME, "w");
vout(fmt1, "Mon", "Tues", "Wed", "Thurs", "Fri");
fclose(stream);
return 0;
}
/****************************************************
Output should be similar to:
Mon Tues Wed Thurs Fri ****************************************************/
void vout(char *fmt, ...)
{
va_list arg_ptr;
va_start(arg_ptr, fmt);
vprintf(fmt, arg_ptr);
va_end(arg_ptr);
}
![]()
printf -- Print Formatted Characters
va_arg - va_end - va_start -- Access
Function Arguments
vfprintf -- Print Argument Data to
Stream
vsprintf -- Print Argument Data to
Buffer
<stdarg.h>
<stdio.h>