_getc_nolock, _getwc_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 _getc_nolock, _getwc_nolock.

Reads a character from a stream.

int _getc_nolock(   
   FILE *stream   
);  
wint_t _getwc_nolock(   
   FILE *stream   
);  

Parameters

stream
Input stream.

See getc, getwc.

These functions are identical to getc and getwc except that they do not lock the calling thread. 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
_gettc_nolockgetc_nolockgetc_nolockgetwc_nolock
RoutineRequired header
getc_nolock<stdio.h>
getwc_nolock<stdio.h> or <wchar.h>

For more compatibility information, see Compatibility in the Introduction.

// crt_getc_nolock.c  
// Use getc to read a line from a file.  
  
#include <stdio.h>  
  
int main()  
{  
    char buffer[81];  
    int i, ch;  
    FILE* fp;  
  
    // Read a single line from the file "crt_getc_nolock.txt".  
    fopen_s(&fp, "crt_getc_nolock.txt", "r");  
    if (!fp)  
    {  
       printf("Failed to open file crt_getc_nolock.txt.\n");  
       exit(1);  
    }  
  
    for (i = 0; (i < 80) && ((ch = getc(fp)) != EOF)  
                         && (ch != '\n'); i++)  
    {  
        buffer[i] = (char) ch;  
    }  
  
    // Terminate string with a null character   
    buffer[i] = '\0';  
    printf( "Input was: %s\n", buffer);  
  
    fclose(fp);  
}  

Line the first.  
Line the second.  

Output

Input was: Line the first.  

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

Show: