Syntax
#include <stdio.h> #include <wchar.h> wint_t fputwc(wchar_t wc, FILE *stream);Description
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.
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.
This example opens a file and uses fputwc to write wide characters to the file.
#include <stdio.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. ****************************************************************************/ }Related Information