Single Character Input Function : getchar()

Single Character Input Function : getchar()

getchar() is used to get or read the input (i.e a single character) at run time.

Declaration:

int getchar(void);

Example Declaration:

char ch;
ch = getchar();

Return Value:

This function return the character read from the keyboard.

Example Program:

/*  Example Program For Single Character Input Function : getchar() In C Programming Language
    little drops @ thiyagaraaj.com
    Coded By:THIYAGARAAJ MP             */

// Header Files
#include<stdio.h>
#include<conio.h>

//Main Function
void main()
{
	char ch;
	ch = getchar();
	printf("Input Char Is :%c",ch);
}

Program Explanation:

Here,declare the  variable ch as  char data type, and then get a value through getchar()library function and store it in the variable ch.And then,print the value of variable ch.

During the program execution, a single character is get or read through the getchar(). The given value is displayed on the screen and the compiler wait for another character to be typed. If you press the enter key/any other characters and then only the given character is  printed through the printf function.