cplusplus.com > reference > cstdio > getchar |
getchar
<stdio.h> |
cplusplus.com |
Get the next character from stdin.
Returns the next character from the standard input (stdin).
It corresponds to: getc(stdin)
Parameters.
Return Value.
The character read is returned as int.
If the End Of File is reached or there has been an error reading,
the function returns EOF.
EOF can indicate either the EndOfFile or an error while reading. You can use ferror()
and feof() to determine which happened.
Portability.
Defined in ANSI-C.
Example.
/* getchar example : typewriter */
#include <stdio.h>
int main ()
{
char 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.
See also.
getc,
putchar,
fgetc,
fopen