Format
#include <stdio.h> int _fgetchar(void);
Language Level: Extension
_fgetchar reads a single character from the stdin
stream. It is equivalent to the following fgetc call:
fgetc(c, stdin);
For portability, use the ANSI/ISO fgetc function instead of _fgetchar.
Return Value
_fgetchar returns the character read. A
return value of EOF indicates an error or end-of-file position.
Use feof or ferror to tell whether the return value indicates an
error or an end-of-file position.
Example
This example gathers a line of input
from stdin using _fgetchar:
#include <stdio.h>
int main(void)
{
char buffer[81];
int i,ch;
printf("Please input a line of characters...\n");
for (i = 0; (i < 80) && ((ch = _fgetchar()) != EOF) && (ch != '\n'); i++)
buffer[i] = ch;
buffer[i] = '\0';
printf("The input line was : %s\n", buffer);
return 0;
/****************************************************************************
The output should be:
Please input a line of characters...
This is a simple program.
The input line was : This is a simple program.
****************************************************************************/
}
![]()
feof -- Test End-of-File
Indicator
ferror -- Test
for Read/Write Errors
fgetc -- Read a
Character
_fputchar --
Write Character
getc - getchar --
Read a Character
_getch - _getche
-- Read Character from Keyboard
<stdio.h>