_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.