_getc_nolock_getwc_nolock

ロックせずにストリームから文字を読み取ります。

構文

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

パラメーター

stream
入力ストリーム。

戻り値

getcgetwc」を参照してください。

解説

これらの関数は、呼び出し元のスレッドをロックしない点を除いて、getc および getwc と同じです。 他のスレッドをロックアウトするオーバーヘッドが発生しないため、処理が速くなる場合があります。 これらの関数は、シングルスレッド アプリケーション、呼び出し元のスコープで既にスレッド分離を処理している場合などのスレッドセーフなコンテキストでのみ使用してください。

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「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>

互換性の詳細については、「 Compatibility」を参照してください。

// 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.

関連項目

ストリーム入出力
fgetcfgetwc
_getch_getwch
putcputwc
ungetcungetwc