### fputwc -- Write Wide Character

Format

>     #include <wchar.h>
>     wint_t fputwc(wint_t wc, FILE *stream);

Language Level: ANSI 93, XPG4
fputwc converts the wide character wc to a multibyte character and writes it to the output stream pointed to by stream at the current position. It also advances the file position indicator appropriately. If the file cannot support positioning requests, or if the stream was opened with append mode, the character is appended to the stream.

The behavior of fputwc is affected by the LC_CTYPE category of the current locale. If you change the category between subsequent operations on the same stream, undefined results can occur. Using non-wide-character functions with fputwc on the same stream results in undefined behavior.

After calling fputwc, flush the buffer or reposition the stream pointer before calling a read function for the stream. After reading from the stream, flush the buffer or reposition the stream pointer before calling fputwc, unless EOF has been reached.

Return Value
fputwc returns the wide character written. If a write error occurs, the error indicator for the stream is set and fputwc returns WEOF. If an encoding error occurs during conversion from wide character to a multibyte character, fputwc sets errno to EILSEQ and returns WEOF.

Example
This example opens a file and uses fputwc to write wide characters to the file.

    #include <stdio.h>
    #include <stdlib.h>
    #include <wchar.h>
    #include <errno.h>

    int main(void)
    {
       FILE    *stream;
       wchar_t *wcs = L"A character string.";
       int     i;

       if (NULL == (stream = fopen("fputwc.out", "w"))) {
          printf("Unable to open: \"fputwc.out\".\n");
          exit(1);
       }

       for (i = 0; wcs[i] != L'\0'; i++) {
          errno = 0;
          if (WEOF == fputwc(wcs[i], stream)) {
             printf("Unable to fputwc() the wide character.\n"
                    "wcs[%d] = 0x%lx\n", i, wcs[i]);
             if (EILSEQ == errno)
                printf("An invalid wide character was encountered.\n");
             exit(1);
          }
       }
       fclose(stream);
       return 0;

       /***************************************************************
          The output file fputwc.out should contain:

          A character string.
       ***************************************************************/
    }

fgetwc -- Read Wide Character from Stream
fputc -- Write Character
_fputchar -- Write Character
fputws -- Write Wide-Character String
_putch -- Write Character to Screen
<stdio.h>
<wchar.h>