Name

getwchar

Synopsis

Reads a wide character from the standard input stream

#include <wchar.h>
wint_tgetwchar( void );

The getwchar() function is the wide-character counterpart to getchar(); it is equivalent to getwc( stdin ) and returns the wide character read. Like getwc(), getwchar() may be implemented as a macro, but because it has no arguments, unforeseen side effects are not likely. A return value of WEOF indicates an error or an attempt to read past the end of the file. In these cases, the function sets the file’s error or end-of-file flag as appropriate.

Example

wint_t wc;

if ( setlocale( LC_CTYPE, "" ) == NULL)
{
  fwprintf( stderr,
            L"Sorry, couldn't change to the system's native locale.\n");
  return 1;
}
while ( (wc =getwchar()) != WEOF ) // or:  (wc = getwc( stdin))
{
  wc = towupper(wc);
  putwchar((wchar_t)wc);        // or:  putwc( (wchar_t)wc, stdout);
}

See Also

fgetwc(); the byte-character functions getc() and getchar(); the output functions fputwc() and putwchar()

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.