Share via


_fgetchar, _fgetwchar

Reads a character from stdin.

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

Return Value

_fgetchar returns the character read as an int or return EOF to indicate an error or end of file. **_**fgetwchar returns, as a wint_t, the wide character that corresponds to the character read or returns WEOF to indicate an error or end of file. For both functions, use feof or ferror to distinguish between an error and an end-of-file condition.

Remarks

These functions read a single character from stdin. The function then increments the associated file pointer (if defined) to point to the next character. If the stream is at end of file, the end-of-file indicator for the stream is set.

_fgetchar is equivalent to fgetc( stdin ). It is also equivalent to getchar, but implemented only as a function, rather than as a function and a macro. _fgetwchar is the wide-character version of _fgetchar.

These functions are not compatible with the ANSI standard.

Generic-Text Routine Mappings

Tchar.h routine

_UNICODE and _MBCS not defined

_MBCS defined

_UNICODE defined

_fgettchar

_fgetchar

_fgetchar

_fgetwchar

Requirements

Function

Required header

_fgetchar

<stdio.h>

_fgetwchar

<stdio.h> or <wchar.h>

For more compatibility information, see Compatibility in the Introduction.

Example

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

.NET Framework Equivalent

See Also

Reference

Stream I/O

fputc, fputwc

getc, getwc