getchar( )
putchar( )
getch( )
putch( )
with suitable examples.
getchar( ) -
It is function from stdio.h header file. This function is used to input a single character.
The enter key is pressed which is followed by the character that is typed. The character that is entered is echoed.
Syntax:
ch=getchar();
Example:
void main()
{
char ch;
ch = getchar();
printf("Input Char Is :%c",ch);
}
During the program execution, a single character gets or read through the getchar(). The given value is displayed on the screen and the compiler waits 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.
putchar( ) -
It is used from standard input (stdio.h) header file.
This function is the other side of getchar. A single character is displayed on the screen.
Syntax:
putchar(ch);
void main()
{
char ch='a';
putchar(ch);
getch();
}
getch( ) -
It is used from the console (conio.h) header file.
This function is used to input a single character.
The character is read instantly and it does not require an enter key to be pressed.
The character type is returned but it does not echo on the screen.
Syntax:
ch=getch();
Where, ch - assigned the character that is returned by getch().
void main()
{
char ch;
ch = getch();
printf("Input Char Is :%c",ch);
}
During the program execution, a single character gets or read through the getch(). The given value is not displayed on the screen and the compiler does not wait for another character to be typed. And then, the given character is printed through the printf function.
putch( )-
It is used from console input output header file (conio.h) This function is a counterpart of getch().
Which means that it will display a single character on the screen.
The character that is displayed is returned.
Syntax:
putch(ch); Where, ch - the character that is to be printed.
void main()
{
char ch='a';
putch(ch)
}