Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

printf(3)

vprintf(3)  —  Subroutines

OSF

NAME

vprintf, vfprintf, vsprintf − Formats a varargs parameter list for output

LIBRARY

Standard I/O Package (libc.a)

SYNOPSIS

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

int vprintf (
const char ∗format,
va_list printarg );

int vfprintf (
FILE ∗stream,
const char ∗format,
va_list printarg );

int vsprintf (
char ∗string,
const char ∗format,
va_list printarg );

PARAMETERS

format
Specifies a character string that contains two types of objects:

- Plain characters, which are copied to the output stream. 

- Conversion specifications, each of which causes zero or more items to be fetched from the varargs parameter lists. 

printarg
Specifies the arguments to be printed.

stream
Specifies the output stream.

string
Specifies the buffer to which output is printed.

DESCRIPTION

The vprintf(), vfprintf(), and vsprintf() functions format and write varargs parameter lists. 

These functions are the same as the printf(), fprintf(), and sprintf() functions, respectively, except that they are not called with a variable number of parameters. Instead, they are called with a parameter list pointer as defined by varargs. 

NOTES

AES Support Level: Full use

EXAMPLE

The following example demonstrates how the vfprintf() function can be used to write an error routine:

#include <stdio.h>
#include <varargs.h>
/∗ error should be called with the syntax:       ∗/
/∗ error(routine_name, Format [, value, . . . ]);
∗/
/∗VARARGS0∗/
void error(va_alist) va_dcl;
/∗ ∗∗  Note that the function name and Format arguments ∗∗
cannot be separately declared because of the ∗∗
definition of varargs.  ∗/  {
   va_list args;
   char ∗fmt;
   void fprintf() , vfprintf() , abort();
   va_start(args);
   /∗
   ∗∗ Display the name of the function that called error
   ∗/
   fprintf(stderr, "ERROR in %s: ", va_arg(args, char ∗));
   /∗
   ∗∗ Display the remainder of the message
   ∗/
   fmt = va_arg(args, char ∗);
   vfprintf(fmt, args);
   va_end(args);
    abort();  }

RELATED INFORMATION

Functions: printf(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026