getchar in c: 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
Get char in c: 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 using getchar function
Getchar function in c: The following program shows the use of getchar function to read characters standard input stream stdio(keyboard).
#include<stdio.h> int main(){ char c; printf("Enter a character\n"); c = getchar(); printf("Character entered: %c", c); return(0); }
Program Output
Enter a character A Character entered: A