function
<cwchar>

fputwc

wint_t fputwc (wchar_t wc, FILE * stream);
Write wide character to stream
Writes the wide character wc to the stream and advances the position indicator.

Because wide characters are represented by multibyte characters in external files, the function may involve writing several bytes to the file, as if wcrtomb was called to translate wc with the stream's internal mbstate_t object.

If the wide character cannot be represented using the multibyte encoding, the function returns WEOF and sets EILSEQ as the value of errno.

If a writing error occurs, the function returns WEOF and sets the error indicator for the stream (ferror).

fputwc and putwc are equivalent, except that putwc may be implemented as a macro in some libraries.

This is the wide character equivalent of fputc (<cstdio>).

Parameters

wc
The wide character to write.
stream
Pointer to a FILE object that identifies an output stream.
The stream shall not have an orientation yet, or be wide-oriented (the first i/o operation on a stream determines whether it is byte- or wide- oriented, see fwide).

Return Value

On success, the character written is returned (wc promoted to a value of type wint_t).
The return type is wint_t to accommodate for the special value WEOF, which indicates failure:
If the wide character could not be interpreted as a valid multibyte character, the function returns WEOF and sets errno to EILSEQ.
If a writing error occurs, the function also returns WEOF and the error indicator (ferror) is set.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* fputwc example */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  wchar_t wc;

  pFile = fopen ("example.txt","w");
  if (pFile!=NULL) {

    for (wc = L'A' ; wc <= L'Z' ; ++wc)
      fputwc ( wc , pFile );

    fclose (pFile);
  }
  return 0;
}


See also