### vfwprintf -- Format Argument Data as Wide Characters and Write to a Stream

Format

>     #include <stdarg.h>
>     #include <stdio.h>
>     #include <wchar.h>
>     int vfwprintf(FILE *stream, const wchar_t *format, va_list arg);

Language Level: ANSI 93
vfwprintf is equivalent to fwprintf, except that the variable argument list is replaced by arg, which the va_start macro (and possibly subsequent va_arg calls) will have initialized. vfwprintf does not invoke the va_end macro.

Note: Because the functions vfwprintf, vswprintf, and vwprintf invoke the va_arg macro, the value of arg after the return is unspecified.

For a complete description, see fwprintf -- Format Data as Wide Characters and Write to a Stream.

Return Value
vfwprintf returns the number of wide characters transmitted.

If an output error occurred, vfwprintf returns a negative value.

Example
This example prints date and time in the form "Monday, April 14, 17:47" followed by pi to five decimal places. Note that date and time may be formatted according to your locale's representation. The printing is done from the vout function, which takes a variable number of arguments and uses vfwprintf to print them to a file.

    #include <stdlib.h>
    #include <stdio.h>
    #include <stdarg.h>
    #include <math.h>
    #include <time.h>
    #include <wchar.h>
    #include <locale.h>

    void vout(FILE *stream, wchar_t *fmt,...);

    int main(void)
    {
       wchar_t *weekday, *month;
       FILE *stream;
       struct tm *newtime;
       time_t ltime;
       struct dtconv *p;

       weekday = (wchar_t *)malloc(sizeof(wchar_t)*20);
       month = (wchar_t *)malloc(sizeof(wchar_t)*20);

       stream = fopen("myfile.dat", "w");    /* Open the stream for writing */

       setlocale(LC_ALL,"");

       time(&ltime);
       newtime = localtime(&ltime);
       p = localdtconv();
       mbstowcs(weekday, p->day_names[newtime->tm_wday], sizeof(wchar_t)*20);
       mbstowcs(month, p->month_names[newtime->tm_mon], sizeof(wchar_t)*20);

       vout(stream, L"%ls, %ls %d, %.2d:%.2d\n",
                weekday, month, newtime->tm_mday,
                newtime->tm_hour, newtime->tm_min);

       vout(stream, L"pi = %.5f\n", 4* atan(1.0));

       fclose(stream);
       return 0;

       /*******************************************************************
          The contents of output file myfile.dat should be similar to:

          Monday, April 14, 17:47
          pi = 3.15149
       *******************************************************************/
    }

    void vout(FILE *stream, wchar_t *fmt, ...)
    {
       va_list arg_ptr;

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

fprintf -- Write Formatted Data to a Stream
printf -- Print Formatted Characters
vfprintf -- Print Argument Data to Stream
vprintf -- Print Argument Data
btowc -- Convert Single Byte to Wide Character
mbrtowc -- Convert Multibyte Character to Wide Character
fwprintf -- Format Data as Wide Characters and Write to a Stream
vswprintf -- Format and Write Wide Characters to Buffer
vwprintf -- Format Argument Data as Wide Characters and Print
wprintf -- Format Data as Wide Characters and Print
<stdarg.h>
<stdio.h>
<wchar.h>