What is the difference between getch() getchar()and getche() in c programming?

2

2 Answers

Jean-Simon Lavoie Profile
FROM: www.daniweb.com/forums/thread37195.html
getchar
This is a standard function that gets a character from the stdin.

Getch
This is a nonstandard function that gets a character from keyboard, does not echo to screen.

Getche
This is a nonstandard function that gets a character from the keyboard, echoes to screen.

Use getchar if you want it to work on all compilers. Use getch or getche on a system that supports it when you want keyboard input without pressing [Enter].

And note that the return value of all three is int! You need this to properly check for EOF.

GOOGLE IS YOUR FRIEND
Florio Potter Profile
Florio Potter answered

getc():
It reads a single character from a given input stream and returns the corresponding integer value (typically ASCII value of read character) on success. It returns EOF on failure.

getchar():
The difference between getc() and getchar() is getc() can read from any input stream, but getchar() reads from standard input. So getchar() is equivalent to getc(stdin).

getch():
getch() is a nonstandard function and is present in conio.h header file which is mostly used by MS-DOS compilers like Turbo C. It is not part of the C standard library or ISO C, nor is it defined by POSIX.

getche()
Like getch(), this is also a non-standard function present in conio.h. It reads a single character from the keyboard and displays immediately on output screen without waiting for enter key.

For more information get help at CodeAvail- Online Computer Science Assignment
help

Answer Question

Anonymous