Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Difference Between getc(), getchar(), getch() and getche()

getc() Vs. getchar() Vs. getch() Vs. getche(): Know the Difference Between getc(), getchar(), getch() and getche()

These are all functions that basically read a given character from the input and then return an integer value for them. This integer, then, returns for accommodating a special value that indicates failure. We generally use the value EOF for this very purpose. In this article, we will discuss the difference between getc(), getchar(), getch() and getche(). But before we do that, let us know a bit more about each of these individually.

What is getc()?

The getc() reads one character from any input and then returns the corresponding value of the integer on success (typically, the ASCII value of the read character). On failure, it then returns the EOF.

Here, Syntax:

int getc(FILE *stream);

What is getchar()?

The primary difference between the getchar() and getc() is that the getc() is capable of reading from any input scheme, while the getchar() is capable of reading from the standard input. Hence, getchar() becomes equivalent to the getc(stdin).

Here, Syntax:

int getchar(void);

What is getch()?

The getch() is a type of non-standard function which is present in the file of conio.h. Mostly, the MS-DOS compilers utilize it, like the Turbo C. It does not fall into a part of the standard library of C or ISO C. It is also not defined by the POSIX.

It is capable of reading a single character from any given keyboard. Since it doesn’t make use of any buffer, the entered character returns immediately without having to wait for the enter key.

Here, Syntax:

int getch();

What is getche()?

Just like gentch(), the getche() is also a non-standard type of function that is present in the conio.h file. It is capable of reading one character from any given keyboard and displaying it immediately on the output screen without the character having to wait for the enter key.

Here, Syntax:

int getche(void);

Difference Between getc(), getchar(), getch() and getche()

Here are the differences between getc(), getchar(), getch() and getche():

Parameters getc() getchar() getch() getche()
Basics The getc() reads one character from any input and then returns the corresponding value of the integer on success (typically, the ASCII value of the read character). On failure, it then returns the EOF. The getchar() is capable of reading from the standard input. Hence, getchar() becomes equivalent to the getc(stdin). The getch() is capable of reading a single character from any given keyboard.

Since it doesn’t make use of any buffer, the entered character returns immediately without having to wait for the enter key.

The getche() is capable of reading one character from any given keyboard and displaying it immediately on the output screen without the character having to wait for the enter key.

Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Application Form, GATE Syllabus, GATE Cut off, GATE Previous Year Question Paper, and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*