ILE C/C++ Run-Time Library Functions


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

Threadsafe: Yes.

Description

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

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

Note:
This function is available when SYSIFCOPT(*IFSIO) is specified on the compilation command, and LOCALETYPE(*CLD) is not specified on the compilation command.

Return Value

The vfwprintf() function returns the number of wide characters transmitted. If an output error occurred, it returns a negative value.

Example that uses vfwprintf()

This example prints the wide character a to a file. 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 <wchar.h> 
#include <stdarg.h> 
#include <locale.h> 
 
void vout (FILE *stream, wchar_t *fmt, ...); 
 
const char ifs_path [] = "tmp/myfile"; 
 
 int main(void)  { 
 
  FILE *stream; 
  wchar_t format [] = L"%lc"; 
 
  setlocale(LC_ALL, "POSIX"); 
  if ((stream = fopen (ifs_path, "w")) == NULL) { 
    printf("Could not open file.\n");
    return (-1);
  } 
  vout (stream, format, L'a'); 
  fclose (stream); 
 
 /*********************************************** 
    The contents of output file tmp/myfile.dat should 
    be a wide char 'a' which in the "POSIX" locale 
    is '0081'x.
 */ 
 
  return (0); 
 
 
 } 
 
 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); 
} 

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]