The getchar () function in C
The function int getchar (void) in Library C takes a character (an unsigned char) from stdin. This function is equivalent to the getc function with the parameter stdin.
The function int getchar (void) in Library C takes a character (an unsigned char) from stdin. This function is equivalent to the getc function with the parameter stdin.
Declare getchar () in C
Here is the declaration for getchar () function in C:
int getchar ( void )
- Parameters: This function does not receive any parameters.
- Return value: This function returns the character read as an unsigned char that is cast to an int or EOF or error.
For example
The following program C illustrates the usage of getchar () function in C:
#include int main () { char c ; printf ( "Nhap ky tu: " ); c = getchar (); printf ( "Ky tu vua nhap: " ); putchar ( c ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function getc () in C
Next lesson: Ham putc () in C
Update 25 May 2019
You should read it
Maybe you are interested
The whole scene of meteorites hitting the Earth during the past 33 years, why can't we feel it? Discovered mysterious signals emanating from a star right next to the Solar System, possibly of aliens NASA reveals its latest snapshot of the Martian surface with a resolution of 1.8 billion pixels Found the second planet of Proxima Centauri, the star closest to the sun 7 most modern astronaut ships on the planet Is Proxima b our 'neighbor' planet?