_fgetc_nolock、_fgetwc_nolock
從資料流讀取一個字元,而不用鎖定執行緒。
int _fgetc_nolock(
FILE *stream
);
wint_t _fgetwc_nolock(
FILE *stream
);
參數
- stream
FILE 結構的指標。
傳回值
請參閱 fgetc、fgetwc。
備註
_fgetc_nolock 和 _fgetwc_nolock 與 fgetc 和 fgetwc分別是相同的,但不會防止由其他執行緒的功能。 因為它們不會造成鎖定其他執行緒的額外負荷,所以可能會比較快。 這些函式只能用在安全執行緒內容 (例如單一執行緒應用程式) 或呼叫範圍已經處理執行緒隔離的地方。
一般文字常式對應
Tchar.h 常式 |
未定義 _UNICODE and _MBCS |
_MBCS 已定義 |
_UNICODE 已定義 |
---|---|---|---|
_fgettc_nolock |
_fgetc_nolock |
_fgetc_nolock |
_fgetwc_nolock |
需求
功能 |
必要的標頭 |
---|---|
_fgetc_nolock |
<stdio.h> |
_fgetwc_nolock |
<stdio.h> 或 <wchar.h> |
如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility) 。
範例
// 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 );
}
Input: crt_fgetc_nolock.txt
Line one.
Line two.
Output
Line one.
Line two.