getwchar
functionThe getwchar
function is equivalent to the getch
function in C. The only difference between the two is that getwchar
works on getch
works on normal characters.
The structure of the getwchar
function is as follows:
wint_t getwchar( void );
The function getwchar
reads a wide character from the standard input. If the sequence of bytes cannot be interpreted as a wide character, then the function returns the value WEOF
.
Note: The reason that
getwchar
returnswint_t
rather thanwchar_t
is to accommodate the special valueWEOF
.
To use the getwchar
function, you need to include the wchar.h
standard library.
getwchar
functionThe following example reads a character from the standard input and outputs it onto the console, unless x
is the input:
Note: You need to provide an input in the
STDIN
of the following code widget (e.g.,abcx
).
#include<stdio.h>#include<wchar.h>int main() {wint_t wchar_in = L'a';do {printf("\nInput any character (or 'x' to terminate): \n");wchar_in = getwchar();putwchar(wchar_in);} while(wchar_in != L'x');return 0;}
Enter the input below
Free Resources