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.
Table of Contents
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
4.5 ★ | 2 Vote
Read More
- DAY function in SQL Server
- MIN function in SQL Server
- MAX function in SQL Server
- SUM function in SQL Server
- The ord () function in Python
- RIGHT function in SQL Server
- Int () function in Python
- AVG function in SQL Server
- 6 Conditional Functions That Make Excel Spreadsheets Smarter
- Hex () function in Python
- ABS function in SQL Server
- SUM for Newbies Only: Excel Experts Use This Function Instead!
- The function id () in Python
- DATEPART function in SQL Server