Read more about parameters of getchar in parameters section
The getcharfunction in C language Reads the next character from the standard input stream.
The getchar function obtains the next character (if present) as an unsigned char converted to an int, from the input stream pointed to by stdin, and advances the associated file position indicator for stdin (if defined). getchar() is equivalent to getc(stdin). It is less efficient than getc(stdin) for cases where it is called within a loop, since getchar has to check the stdin value every time it is called.
The getcharfunction takes 1
parameter:
•
void ``: Indicates that the function takes no arguments
Reads the next character from the standard input (`stdin`) and returns it as an `unsigned char` cast to an `int`. Returns `EOF` if the end-of-file is reached or an error occurs.
The getchar function return value :
Returns the character read as an unsigned char cast to an int or EOF on end of file or error
Use feof() and ferror() to distinguish between end-of-file and error
Output
This example demonstrates basic usage of getchar to read characters from standard input and echo them back to the console.