We recommend using Visual Studio 2017

_getchar_nolock, _getwchar_nolock


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at _getchar_nolock, _getwchar_nolock.

Reads a character from standard input.

int _getchar_nolock( void );  
wint_t _getwchar_nolock( void );  

See getchar, getwchar.

_getchar_nolock and _getwchar_nolock are identical to getchar and getwchar except that they are not protected from interference by other threads. They might be faster because they do not incur the overhead of locking out other threads. Use these functions only in thread-safe contexts such as single-threaded applications or where the calling scope already handles thread isolation.

Generic-Text Routine Mappings

Tchar.h routine_UNICODE and _MBCS not defined_MBCS defined_UNICODE defined
RoutineRequired header
_getwchar_nolock<stdio.h> or <wchar.h>

The console is not supported in Windows 8.x Store 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 Windows 8.x Store apps. For more compatibility information, see Compatibility.

// crt_getchar_nolock.c  
// Use _getchar_nolock to read a line from stdin.   
#include <stdio.h>  
int main()  
    char buffer[81];  
    int i, ch;  
    for (i = 0; (i < 80) && ((ch = _getchar_nolock()) != EOF)  
                         && (ch != '\n'); i++)  
        buffer[i] = (char) ch;  
    // Terminate string with a null character   
    buffer[i] = '\0';  
    printf( "Input was: %s\n", buffer);  

This textInput was: This text  

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