### vfprintf -- Print Argument Data to Stream

Format

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

Language Level: ANSI, XPG4, Extension
vfprintf formats and writes a series of characters and values to the output stream. vfprintf works just like fprintf, 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, fprintf can have a list of arguments, but the number of arguments in that list is fixed when you compile the program.

vfprintf 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 printf. For a description of the format string, see printf -- Print Formatted Characters.

In extended mode, vfprintf also converts floating-point values of NaN and infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case and sign of the string is determined by the format specifiers.

If you specify a null string, on OS/2 and Windows, for the %s or %ls format specifier, vfprintf prints (null). (In previous releases of the C/C++ run-time library, vfprintf produced no output for a null string.)

Return Value
If successful, vfprintf returns the number of bytes written to stream. If an error occurs, the function returns a negative value.

Example
This example prints out a variable number of strings to an output file.

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

    #if (1 == __TOS_OS2__)
      #define FILENAME "myfile.dat"      /* OS/2 file name */
    #else
      #define FILENAME "myfile.dat    /* Windows file name */
    #endif

    void vout(FILE *stream, char *fmt, ...);
    char fmt1 [] = "%s  %s  %s\n";

    int main(void)
    {
       FILE *stream;

       stream = fopen(FILENAME, "w");
       vout(stream, fmt1, "Sat", "Sun", "Mon");
       fclose(stream);
       return 0;

       /*****************************************************
          After running the program,
          the output file should contain:

          Sat  Sun  Mon
       *****************************************************/
    }

    void vout(FILE *stream, char *fmt, ...)

    {
       va_list arg_ptr;

       va_start(arg_ptr, fmt);
       vfprintf(stream, fmt, arg_ptr);
       va_end(arg_ptr);
    }

fprintf -- Write Formatted Data to a Stream
printf -- Print Formatted Characters
va_arg - va_end - va_start -- Access Function Arguments
vprintf -- Print Argument Data
vsprintf -- Print Argument Data to Buffer
vswprintf -- Format and Write Wide Characters to Buffer
<stdarg.h>
<stdio.h>