vprintf() — Print Argument Data

Format

#include <stdarg.h>
#include <stdio.h>
int vprintf(const char *format, va_list arg_ptr);

Language Level: ANSI

Threadsafe: Yes.

Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE and LC_NUMERIC categories of the current locale. The behavior might also be affected by the LC_UNI_CTYPE category of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.

Description

The vprintf() function formats and prints a series of characters and values to stdout. The vprintf() function works just like the printf()function, 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, the printf() function can have a list of arguments, but the number of arguments in that list is fixed when you compile the program.

The vprintf() function 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 the printf() function.

Return Value

If successful, the vprintf() function returns the number of bytes written to stdout. If an error occurs, the vprintf() function returns a negative value. The value of errno may be set to ETRUNC.

Example that uses vprintf()

This example prints out a variable number of strings to stdout.

#include <stdarg.h>
#include <stdio.h>
 
void vout(char *fmt, ...);
char fmt1 [] = "%s  %s  %s   %s   %s \n";
 
int main(void)
{
   FILE *stream;
   stream = fopen("mylib/myfile", "w");
 
   vout(fmt1, "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);
}
 
/******************  Output should be similar to:  ****************
 
Mon  Tues  Wed   Thurs   Fri
*/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]