Share via


_getc_nolock、_getwc_nolock

读取流的一个字符。

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

参数

  • stream
    输入流。

返回值

请参见getc、getwc

备注

这些函数与 getc 和 getwc 是相同,只是不阻止调用线程。 它们可能更快,因为它们不会产生锁定其他线程的开销。 仅在线程安全的上下文中使用这些函数,如单线程应用程序或调用范围已经处理线程隔离。

一般文本例程映射

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.

Output

Input was: Line the first.

.NET Framework 等效项

请参见

参考

流 I/O

fgetc、fgetwc

_getch、_getwch

putc、putwc

ungetc、ungetwc