comparison between getchar(), getche() and getch() functions in “C” language

getchar() 

This function helps us to take input for a single character.

Header file : stdio.h

Example:

char ch;

ch=getchar();

putchar()

This function helps us to display a single character

header file : stdio.h

Example:

putchar(ch);

putchar(‘A’);

Example:

#include <stdio.h>
#include<conio.h>

int main()
{
char ch;
printf(“Enter any character “);
ch=getchar();
printf(“Entered character is %c\n”,ch);
putchar(ch);
return 0;
}

output:

Enter any character k
Entered character is k
k

getche()

This function helps us to take input for a single character

header file :       conio.h

Example:

char ch;

ch=getche();

getch()

This function helps us to take input for a single character

header file :       conio.h

char ch;

ch=getch();

putch()

This function helps us to display a single character

header file         : conio.h

putch(ch);

putch(‘A’);

#include <stdio.h>
#include<conio.h>

int main()
{
char ch;
printf(“Enter any character “);
ch=getche();
printf(“\n\nEntered character is %c\n”,ch);
putchar(ch);
putch(ch);
return 0;
}

output:

Enter any character g

Entered character is g
gg

 

comparison between getchar(), getche() and getch() functions

getchar() :

Entered character is displayed and to move ahead we are required to press enter.

getche()  :

Entered character is displayed and we automatically move ahead.

getch()   :

Entered character is not displayed and we automatically move ahead.

#include <stdio.h>
#include<conio.h>

int main()
{
char ch;
printf(“Enter any character “);
ch=getch();
printf(“\n\nEntered character is %c\n”,ch);
putchar(ch);
putch(ch);
return 0;
}

output:

Enter any character

Entered character is h
hh

Leave a Reply

Your email address will not be published. Required fields are marked *

Number Of Visitors

0270408