_fgetc_nolock _fgetwc_nolock
從資料流讀取字元,而不致鎖定的執行緒。
int _fgetc_nolock(
FILE *stream
);
wint_t _fgetwc_nolock(
FILE *stream
);
參數
- stream
指標FILE結構。
傳回值
Seefgetc fgetwc.
備註
_fgetc_nolock與_fgetwc_nolock等於fgetc和fgetwc,分別不同之處在於它們並不受干擾從其他執行緒。 它們可能會更快,因為它們不會造成其他執行緒所鎖定的額外負荷。 這些函式僅在使用安全執行緒的內容,例如單一執行緒的應用程式,或呼叫的範圍已經處理執行緒隔離。
泛用文字常式對應
Tchar.h 常式 |
_Unicode 之後,未定義的 _MBCS |
定義的 _MBCS |
定義 _unicode 之後 |
---|---|---|---|
_fgettc_nolock |
_fgetc_nolock |
_fgetc_nolock |
_fgetwc_nolock |
需求
Function |
所需的標頭 |
---|---|
_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.
Output
Line one.
Line two.