Name
getchar
Synopsis
Reads a character from the standard input stream
#include <stdio.h>
intgetchar
( void );
The function call getchar()
is equivalent to getc(stdin)
.
Like getc()
, getchar()
may be implemented as a macro.
As it has no arguments, however, unforeseen side effects are
unlikely.
getchar()
returns the
character read. A return value of EOF
indicates an error or an attempt to
read past the end of the input stream. In these cases the function
sets the error or end-of-file flag for stdin
as appropriate.
Example
char file_name[256};
int answer;
/* ... */
fprintf( stderr, "Are you sure you want to replace the file \"%s\"?\n",
file_name );
answer = tolower(getchar
());
if ( answer != 'y' )
exit( -1 );
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.