1,371 views
1 votes
1 votes
what is difference between getc()  getch(), getche(),getchar()???

is getc() and getchar() is same???

1 Answer

0 votes
0 votes

Firstly, getch() and getche() are non standard library functions found in conio.h. Hence, they are useless and should never be used (nor the Turbo C/C++ compilers).

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 (Source:conio.h)
Like above functions, it reads also a single character from keyboard. But it does not use any buffer, so the entered character is immediately returned without waiting for the enter key.

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.

Related questions

0 votes
0 votes
1 answer
1
Khushal Kumar asked Jul 6, 2017
338 views
if getc returns an integer value, then why is it returning the value that a user inputs.#include <stdio.h>int main(){ printf("%c", getc(stdin)); return(0);}
7 votes
7 votes
2 answers
2
Meenakshi Sharma asked Sep 5, 2016
3,644 views
consider the statements putchar (getchar());putchar (getchar());if a b is the input , the output will be a)ab b)a b c)an error message d)this...