_fgetchar、_fgetwchar
從 stdin 讀取字元。
int _fgetchar( void );
wint_t _fgetwchar( void );
傳回值
_fgetchar 傳回作為 int 讀取的字元或傳回EOF 表示錯誤或檔案結尾。 **_**fgetwchar 傳回對應至讀取的字元寬字元或傳回 WEOF 以指出錯誤或檔案結尾,如 wint_t。 對於兩個函式,請使用 feof 或 ferror 區別錯誤和文件結尾條件。
備註
這些函式讀取來自 stdin 的單一字元。 函式會將關聯的檔案指標 (如果有定義)指向下一個字元。 如果資料流已在檔案結尾,資料流的檔案結尾標記會被設定。
_fgetchar 相當於 fgetc( stdin )。 它也相當於 getchar,不過,只有實作為函式,而不是函式和巨集。 _fgetwchar 是 _fgetchar的寬字元版本。
這些函式與 ANSI 標準不相容。
一般文字常式對應
Tchar.h 常式 |
未定義 _UNICODE and _MBCS |
已定義 _MBCS |
已定義 _UNICODE |
---|---|---|---|
_fgettchar |
_fgetchar |
_fgetchar |
_fgetwchar |
需求
Function |
必要的標頭 |
---|---|
_fgetchar |
<stdio.h> |
_fgetwchar |
<stdio.h> 或 <wchar.h> |
Windows 市集 應用程式不支援主控台。 與主控台關聯的標準資料流控制代碼 (stdin、stdout 和 stderr) 必須重新導向,然後 C 執行階段函式才能在 Windows 市集 應用程式中使用它們。 如需相容性的詳細資訊,請參閱相容性。
範例
// crt_fgetchar.c
// This program uses _fgetchar 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 )
{
char buffer[81];
int i, ch;
// Read in first 80 characters and place them in "buffer":
ch = _fgetchar();
for( i=0; (i < 80 ) && ( feof( stdin ) == 0 ); i++ )
{
buffer[i] = (char)ch;
ch = _fgetchar();
}
// Add null to end string
buffer[i] = '\0';
printf( "%s\n", buffer );
}