Share via


_fgetchar, _fgetwchar

stdin 讀取字元。

語法

int _fgetchar( void );
wint_t _fgetwchar( void );

傳回值

_fgetchar 傳回讀取為 int 或 的 EOF 字元,以指出檔案的錯誤或結尾。 _fgetwchar會傳回 ,做為 wint_t ,對應至讀取或傳回 WEOF 的寬字元,表示檔案的錯誤或結尾。 針對這兩個函式,使用 feofferror 來區分錯誤與檔案結尾條件。

備註

這些函式會從 stdin 讀取單一字元。 此函式接著會增加相關聯的檔案指標 (定義時) 以指向下一個字元。 如果資料流位於檔案結尾,則會設定資料流的檔案結尾指標。

_fgetchar 等於 fgetc( stdin )。 它也相當於 getchar ,但只實作為函式,而不是做為函式和宏。 _fgetwchar 是寬字元版本的 _fgetchar

這些函式與 ANSI 標準不相容。

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

泛型文字常式對應

Tchar.h 常式 _UNICODE_MBCS 未定義 _MBCS 定義 _UNICODE 定義
_fgettchar _fgetchar _fgetchar _fgetwchar

需求

函式 必要的標頭
_fgetchar <stdio.h>
_fgetwchar <stdio.h > 或 < wchar.h>

通用 Windows 平臺 (UWP) 應用程式中不支援主控台。 與主控台 stdinstdout 、 和 stderr 相關聯的標準資料流程控制碼必須先重新導向,C 執行時間函式才能在 UWP 應用程式中使用這些控制碼。 如需相容性詳細資訊,請參閱相容性

範例

// 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 );
}

      Line one.
Line two.Line one.
Line two.

另請參閱

資料流 I/O
fputc, fputwc
getc, getwc