Skip to content

Latest commit

 

History

History
112 lines (83 loc) · 3.01 KB

getc-nolock-getwc-nolock.md

File metadata and controls

112 lines (83 loc) · 3.01 KB
title description ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords
_getc_nolock, _getwc_nolock
Learn more about: _getc_nolock, _getwc_nolock
4/2/2020
_getc_nolock
_getwc_nolock
_o__getc_nolock
_o__getwc_nolock
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
getc_nolock
_gettc_nolock
_getc_nolock
getwc_nolock
gettc_nolock
_getwc_nolock
characters, reading
_getc_nolock function
_getwc_nolock function
getwc_nolock function
streams, reading characters from
reading characters from streams
getc_nolock function
gettc_nolock function
_gettc_nolock function

_getc_nolock, _getwc_nolock

Reads a character from a stream without locking.

Syntax

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

Parameters

stream
Input stream.

Return value

See getc, getwc.

Remarks

These functions are identical to getc and getwc except that they don't lock the calling thread. They might be faster because they don't 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.

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
_gettc_nolock getc_nolock getc_nolock getwc_nolock

Requirements

Routine Required header
getc_nolock <stdio.h>
getwc_nolock <stdio.h> or <wchar.h>

For more compatibility information, see Compatibility.

Example

// 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);
}

Input: crt_getc_nolock.txt

Line the first.
Line the second.

Output

Input was: Line the first.

See also

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