Share via


_getc_nolock, _getwc_nolock

Membaca karakter dari aliran tanpa mengunci.

Sintaks

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

Parameter

stream
Aliran input.

Nilai hasil

Lihat getc, getwc.

Keterangan

Fungsi-fungsi ini identik getc dengan dan getwc kecuali bahwa fungsi tersebut tidak mengunci utas panggilan. Mereka mungkin lebih cepat karena mereka tidak menimbulkan overhead penguncian utas lain. Gunakan fungsi-fungsi ini hanya dalam konteks aman utas seperti aplikasi utas tunggal atau di mana cakupan panggilan sudah menangani isolasi utas.

Secara default, status global fungsi ini dicakup ke aplikasi. Untuk mengubah perilaku ini, lihat Status global di CRT.

Pemetaan rutin teks generik

Rutinitas Tchar.h _UNICODE dan _MBCS tidak ditentukan _MBCS Didefinisikan _UNICODE Didefinisikan
_gettc_nolock getc_nolock getc_nolock getwc_nolock

Persyaratan

Rutin Header yang diperlukan
getc_nolock <stdio.h>
getwc_nolock <stdio.h> atau <wchar.h>

Untuk informasi kompatibilitas selengkapnya, lihat Kompatibilitas.

Contoh

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

Lihat juga

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