Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

_fgetchar, _fgetwchar 

Reads a character from stdin.


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

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

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

Function Required header Compatibility

_fgetchar

<stdio.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_fgetwchar

<stdio.h> or <wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

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

Input

Line one.
Line two.

Output

Line one.
Line two.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.