fputws -- Write Wide-Character String

Format

#include <wchar.h>
int fputws(const wchar_t *wcs, FILE *stream);

Language Level: ANSI, XPG4
fputws converts the wide-character string wcs to a multibyte-character string and writes it to stream as a multibyte character string. It does not write the terminating null byte.

The behavior of fputws 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 fputws on the same stream results in undefined behavior.

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

Return Value
fputws returns a non-negative value if successful. If a write error occurs, the error indicator for the stream is set and fputws returns -1. If an encoding error occurs in converting the wide characters to multibyte characters, fputws sets errno to EILSEQ and returns -1.

Example
This example opens a file and writes a wide-character string to the file using fgetws.

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <errno.h>
int main(void)
{
   FILE    *stream;
   wchar_t *wcs = L"This test string should not return -1";
   if (NULL == (stream = fopen("fputws.out", "w"))) {
      printf("Unable to open: \"fputws.out\".\n");
      exit(1);
   }
   errno = 0;
   if (EOF == fputws(wcs, stream)) {
      printf("Unable to complete fputws() function.\n");
      if (EILSEQ == errno)
         printf("An invalid wide character was encountered.\n");
      exit(1);
   }
   fclose(stream);
   return 0;
   /************************************************************
      The output file fputws.out should contain:
      This test string should not return -1
   ************************************************************/
}


fgetws -- Read Wide-Character String from Stream
fputs -- Write String
fputwc -- Write Wide Character
<stdio.h>
<wchar.h>