Returns the next character from the standard input (stdin).
It is equivalent to calling getc with stdin as argument.
Parameters
(none)
Return Value
On success, the character read is returned (promoted to an int value).
The return type is int to accommodate for the special value EOF, which indicates failure:
If the standard input was at the end-of-file, the function returns EOF and sets the eof indicator (feof) of stdin.
If some other reading error happens, the function also returns EOF, but sets its error indicator (ferror) instead.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13
/* getchar example : typewriter */
#include <stdio.h>
int main ()
{
int c;
puts ("Enter text. Include a dot ('.') in a sentence to exit:");
do {
c=getchar();
putchar (c);
} while (c != '.');
return 0;
}
A simple typewriter. Every sentence is echoed once ENTER has been pressed until a dot (.) is included in the text.