putwchar() — Write Wide Character to stdout
Format
#include <wchar.h>
wint_t putwchar(wint_t wc);
Language Level
ANSI
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE category of the current locale. This behavior might also be affected by the LC_UNI_CTYPE category of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Integrated File System Interface
This function is not available when SYSIFCOPT(*NOIFSIO) is specified on the compilation command.
Wide Character Function
See Wide Characters for more information.
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)
.
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
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.
**************************************************************/
}