_getc_nolock_getwc_nolock

從資料流讀取字元,不需要鎖定。

語法

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

參數

stream
輸入資料流。

傳回值

請參閱:getcgetwc

備註

這些函式與 getcgetwc 相同,不同之處在於其不會鎖定呼叫執行緒。 因為其不會造成鎖定其他執行緒的額外負荷,所以可能會比較快。 這些函式只能用在安全執行緒內容 (例如單一執行緒應用程式) 或呼叫範圍已經處理執行緒隔離的地方。

根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態

一般文字常式對應

Tchar.h 常式 _UNICODE_MBCS 未定義 _MBCS 已定義 _UNICODE 已定義
_gettc_nolock getc_nolock getc_nolock getwc_nolock

需求

常式 必要的標頭
getc_nolock <stdio.h>
getwc_nolock <stdio.h> 或 <wchar.h>

如需相容性詳細資訊,請參閱相容性

範例

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

輸入︰crt_getc_nolock.txt

Line the first.
Line the second.

輸出

Input was: Line the first.

另請參閱

資料流 I/O
fgetc, fgetwc
_getch_getwch
putcputwc
ungetc, ungetwc