[Previous] [Contents] [Index] [Next]

vprintf()

Write formatted output to a file

Synopsis:

#include <stdio.h>
#include <stdarg.h>

int vprintf( const char* format, 
             va_list arg );

Library:

libc

Description:

The vprintf() function writes output to the file stdout, under control of the argument format. For information about the format string, see the description of printf().

The vprintf() function is equivalent to the printf() function, with the variable argument list replaced with arg, which has been initialized by the va_start() macro.

Returns:

The number of characters written, or a negative value if an output error occurred (errno is set).

Examples:

The following shows the use of vprintf() in a general error message routine:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void errmsg( char* format, ... )
  {
    va_list arglist;

    printf( "Error: " );
    va_start( arglist, format );
    vprintf( format, arglist );
    va_end( arglist );
  }

int main( void )
  {
    errmsg( "%s %d %s", "Failed", 100, "times" );
    return EXIT_SUCCESS;
  }

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, fprintf(), printf(), sprintf(), va_arg(), va_end(), va_start(), vfprintf(), vsprintf()


[Previous] [Contents] [Index] [Next]