Syntax
#include <stdio.h> #include <wchar.h> int fputws(const wchar_t *wcs, FILE *stream);Description
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.
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.
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.
#include <stdio.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 ****************************************************************************/ }Related Information