Syntax
#include <stdarg.h> #include <stdio.h> int vprintf(const char *format, va_list arg_ptr);Description
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.
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. See Infinity and NaN Support for more information on infinity and NaN values.
If successful, vprintf returns the number of bytes written to stdout. If an error occurs, vprintf returns a negative value.
This example prints out a variable number of strings to stdout.
#include <stdarg.h> #include <stdio.h> void vout(char *fmt, ...); int main(void) { char fmt1[] = "%s %s %s\n"; vout(fmt1, "Sat", "Sun", "Mon"); return 0; /**************************************************************************** The output should be: Sat Sun Mon ****************************************************************************/ } void vout(char *fmt, ...) { va_list arg_ptr; va_start(arg_ptr, fmt); vprintf(fmt, arg_ptr); va_end(arg_ptr); }Related Information