ILE C/C++ Run-Time Library Functions


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.

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 | Table of Contents | Index ]