Get the next character from stdin.
#include <stdio.h> int getchar(void);
The getchar() function reads a character from the stdin stream.
The function getchar() is implemented as getc(stdin) and as such getchar's return may be delayed or optimized out of program order if stdin is buffered. For most implementations stdin is line buffered.
getchar() returns the value of the next character from stdin as an int if it is successful. getchar() returns EOF if it reaches an end-of-file or an error occurs.
#include <stdio.h> int main(void) { // We use int, not char, because EOF value is outside // of char's range. int c; printf("Enter characters to echo, * to quit.\n"); // characters entered from the console are echoed // to it until a * character is read while ( (c = getchar()) != '*') putchar(c); printf("\nDone!\n"); return 0; } Output: Enter characters to echo, * to quit. I'm experiencing deja-vu * I'm experiencing deja-vu Done!