_getchar_nolock, _getwchar_nolock
Reads a character from standard input.
int _getchar_nolock( void ); wint_t _getwchar_nolock( void );
_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.
| Tchar.h routine | _UNICODE and _MBCS not defined | _MBCS defined | _UNICODE defined |
|---|---|---|---|
| _gettchar_nolock | _getchar_nolock | _getchar_nolock | _getwchar_nolock |
| Routine | Required header | Compatibility |
|---|---|---|
| _getchar_nolock | <stdio.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _getwchar_nolock | <stdio.h> or <wchar.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
For more compatibility information, see Compatibility in the Introduction.
// 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);
}
Input
This text
Output
Input was: This text