Format
#include <wchar.h> wint_t putwchar(wint_t wc);
Language Level: ANSI
Threadsafe: Yes.
Description
The putwchar() function converts the wide character wc to a multibyte character and writes it to stdout. A call to the putwchar() function is equivalent to putwc(wc, stdout).
The behavior of this function is affected by the LC_CTYPE category of the current locale. Using a non-wide-character function with the putwchar() function on the same stream results in undefined behavior. After calling the putwchar()function, flush the buffer or reposition the stream pointer before calling a write function for the stream, unless EOF has been reached. After a write operation on the stream, flush the buffer or reposition the stream pointer before calling the putwchar() function.
Return Value
The putwchar() function returns the wide character written. If a write error occurs, the putwchar() function sets the error indicator for the stream and returns WEOF. If an encoding error occurs when a wide character is converted to a multibyte character, the putwchar() function sets errno to EILSEQ and returns WEOF.
For information about errno values for putwc(), see "fputc() -- Write Character".
Example that uses putwchar()
This example uses the putwchar() function to write the string in wcs.
#include <stdio.h> #include <wchar.h> #include <errno.h> #include <stdlib.h> int main(void) { wchar_t *wcs = L"A character string."; int i; for (i = 0; wcs[i] != L'\0'; i++) { errno = 0; if (WEOF == putwchar(wcs[i])) { printf("Unable to putwchar() the wide character.\n"); printf("wcs[%d] = 0x%lx\n", i, wcs[i]); if (EILSEQ == errno) printf("An invalid wide character was encountered.\n"); exit(EXIT_FAILURE); } } return 0; /************************************************************** The output should be similar to : A character string. **************************************************************/ }
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.