getchar : <stdio.h> library function

The function int getchar(void); gets a single character from standard input stream stdin. Calling getchar function is same as to calling getc with stdin as argument.

Function prototype of getchar

int getchar(void);
  • NONE

Return value of getchar

This function returns the character read from the stdio stream(type casted to an int value) otherwise returns EOF in case of error or If end of file is reached.

C program to show the use of getchar function

The following program shows the use of getchar function to read characters standard input stream stdio(keyboard).


int main(){
   char c;

   printf("Enter a character\n");
   c = getchar();
   printf("Character entered: %c", c);

Program Output
Enter a character
Character entered: A