fputwc, putwc

Defined in header <wchar.h>
wint_t fputwc( wchar_t ch, FILE *stream );
(since C95)
wint_t putwc( wchar_t ch, FILE *stream );
(since C95)

Writes a wide character ch to the given output stream stream. putwc() may be implemented as a macro and may evaluate stream more than once.


ch - wide character to be written
stream - the output stream

Return value

Returns a copy of ch on success.

On failure, returns WEOF and sets the error indicator (see ferror()) on stream.

If an encoding error occurred, additionally sets errno to EILSEQ.


#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <errno.h>
int main(void)
    setlocale(LC_ALL, "en_US.utf8");
    errno = 0;
    if (fputwc(L'🍌', stdout) == WEOF) {
        if (errno == EILSEQ)
            puts("Encoding error in fputwc.");
            puts("I/O error in fputwc.");
        return EXIT_FAILURE;




  • C11 standard (ISO/IEC 9899:2011):
    • The fputwc function (p: 422-423)
    • The putwc function (p: 424)
  • C99 standard (ISO/IEC 9899:1999):
    • The fputwc function (p: 368)
    • The putwc function (p: 370)

See also

writes a character to a file stream
writes a wide string to a file stream
gets a wide character from a file stream
C++ documentation for fputwc

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.