Share via


_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
fputc, fputwc
getc, getwc