Condividi tramite


_fgetchar, _fgetwchar

Legge un carattere da un flusso stdin.

Sintassi

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

Valore restituito

_fgetchar restituisce il carattere letto come o restituisce intEOF per indicare un errore o una fine del file. _fgetwchar restituisce, come , wint_til carattere wide che corrisponde al carattere letto o restituisce WEOF per indicare un errore o una fine del file. Per entrambe le funzioni, usare feof o ferror per distinguere tra un errore e una condizione di fine del file.

Osservazioni:

Queste funzioni leggono un singolo carattere da stdin. La funzione quindi incrementa il puntatore del file associato (se definito) per puntare al carattere successivo. Se il flusso è alla fine del file, viene impostato l'indicatore di fine del file per il flusso.

_fgetchar è pari a fgetc( stdin ). Equivale anche a getchar, ma implementato solo come funzione, anziché come funzione e macro. _fgetwchar è la versione a caratteri wide di _fgetchar.

Queste funzioni non sono compatibili con lo standard ANSI.

Per impostazione predefinita, lo stato globale di questa funzione è limitato all'applicazione. Per modificare questo comportamento, vedere Stato globale in CRT.

Mapping di routine di testo generico

Routine Tchar.h _UNICODE e _MBCS non definito _MBCS Definito _UNICODE Definito
_fgettchar _fgetchar _fgetchar _fgetwchar

Requisiti

Funzione Intestazione obbligatoria
_fgetchar <stdio.h>
_fgetwchar <stdio.h> o <wchar.h>

La console non è supportata nelle app piattaforma UWP (Universal Windows Platform) (UWP). Gli handle di flusso standard associati alla console,stdinstdout e stderr, devono essere reindirizzati prima che le funzioni di runtime C possano usarle nelle app UWP. Per altre informazioni sulla compatibilità, vedere Compatibility (Compatibilità).

Esempio

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

Vedi anche

I/O di flusso
fputc, fputwc
getc, getwc