Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 2.95 KB

getchar-getwchar.md

File metadata and controls

89 lines (64 loc) · 2.95 KB
descriptiontitlems.dateapi_nameapi_locationapi_typetopic_typef1_keywordshelpviewer_keywords
Learn more about: getchar, getwchar
getchar, getwchar
06/23/2020
getchar
getwchar
_o_getchar
_o_getwchar
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-stdio-l1-1-0.dll
DLLExport
apiref
getwchar
GetChar
gettchar function
characters, reading
getwchar function
_gettchar function
standard input, reading from

getchar, getwchar

Reads a character from standard input.

Syntax

intgetchar(); wint_tgetwchar();

Return value

Returns the character read. These functions wait for input and don't return until input is available.

To indicate a read error or end-of-file condition, getchar returns EOF, and getwchar returns WEOF. For getchar, use ferror or feof to check for an error or for end of file.

Remarks

Each routine reads a single character from stdin and increments the associated file pointer to point to the next character. getchar is the same as _fgetchar, but it's implemented as a function and as a macro.

These functions also lock the calling thread and are thread-safe. For a non-locking version, see _getchar_nolock, _getwchar_nolock.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Generic-text routine mappings

TCHAR.H routine_UNICODE and _MBCS not defined_MBCS defined_UNICODE defined
_gettchargetchargetchargetwchar

Requirements

RoutineRequired header
getchar<stdio.h>
getwchar<stdio.h> or <wchar.h>

The console isn't supported in Universal Windows Platform (UWP) apps. The standard stream handles that are associated with the console, stdin, stdout, and stderr, must be redirected before C run-time functions can use them in UWP apps. For more compatibility information, see Compatibility.

Example

// crt_getchar.c// Use getchar to read a line from stdin.#include<stdio.h>intmain() { charbuffer[81]; inti, ch; for (i=0; (i<80) && ((ch=getchar()) !=EOF) && (ch!='\n'); i++) { buffer[i] = (char) ch; } // Terminate string with a null characterbuffer[i] ='\0'; printf( "Input was: %s\n", buffer); }
 This textInput was: This text 

See also

Stream I/O
getc, getwc
fgetc, fgetwc
_getch, _getwch
putc, putwc
ungetc, ungetwc

close