_fgetc_nolock_fgetwc_nolock

在不锁定的情况下从流中读取字符。

语法

int _fgetc_nolock(
   FILE *stream
);
wint_t _fgetwc_nolock(
   FILE *stream
);

参数

stream
指向 FILE 结构的指针。

返回值

请参阅 fgetcfgetwc

注解

_fgetc_nolock_fgetwc_nolock 分别与 fgetcfgetwc 相同,只不过它们可能受到其他线程的影响。 它们可能更快,因为它们不会产生锁定其他线程的开销。 仅在线程安全的上下文中使用这些函数,如单线程应用程序或调用范围已经处理线程隔离。

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

一般文本例程映射

Tchar.h 例程 _UNICODE_MBCS 未定义 _MBCS 已定义 _UNICODE 已定义
_fgettc_nolock _fgetc_nolock _fgetc_nolock _fgetwc_nolock

要求

函数 必需的标头
_fgetc_nolock <stdio.h>
_fgetwc_nolock <stdio.h> 或 <wchar.h>

有关兼容性的详细信息,请参阅 兼容性

示例

// crt_fgetc_nolock.c
// This program uses getc to read the first
// 80 input characters (or until the end of input)
// and place them into a string named buffer.

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   FILE *stream;
   char buffer[81];
   int  i, ch;

   // Open file to read line from:
   if( fopen_s( &stream, "crt_fgetc_nolock.txt", "r" ) != 0 )
      exit( 0 );

   // Read in first 80 characters and place them in "buffer":
   ch = fgetc( stream );
   for( i=0; (i < 80 ) && ( feof( stream ) == 0 ); i++ )
   {
      buffer[i] = (char)ch;
      ch = _fgetc_nolock( stream );
   }

   // Add null to end string
   buffer[i] = '\0';
   printf( "%s\n", buffer );
   fclose( stream );
}

输入:crt_fgetc_nolock.txt

Line one.
Line two.

输出

Line one.
Line two.

另请参阅

流 I/O
fputcfputwc
getcgetwc