Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

printf, fprintf, sprintf, NLprintf, NLfprintf, NLsprintf

     vprintf, vfprintf, vsprintf

Purpose

     Formats a varargs parameter list for output.

Library

     Standard I/O Library (libc.a)

Syntax

     #include <stdio.h>
     #include <varargs.h>

     int vprintf (format, argp)                char *format;
     char *format;                             va_list argp;
     va_list argp;
                                               int vsprintf (s, format, argp)
     int vfprintf (stream, format, argp)       char *s, *format;
     FILE *stream;                             va_list argp;
     Description

     The  vprintf, vfprintf,  and vsprintf  subroutines format
     and write varargs parameter lists.   They are the same as
     the  printf, fprintf,  and  sprintf subroutines,  respec-
     tively, 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."

     Example

     The following example demonstrates  how the vfprintf sub-
     routine could 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;

          va_start(args);
          /*
          ** Display the name of the function that called error
          */
          (void) fprintf(stderr, "ERROR in %s: ", va_arg(args, char *));
          /*
          ** Display the remainder of the message
          */
          fmt = va_arg(args, char *);
          (void) vfprintf(fmt, args);
          va_end(args);
          (void) abort();
       }

     Related Information

     In  this  book:   "printf,  fprintf,  sprintf,  NLprintf,
     NLfprintf, NLsprintf."

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