Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between getch() and getchar()?

Tags:

What is the exact difference between the getch and getchar functions?

like image 343
bubble Avatar asked Feb 07 '12 16:02

bubble


People also ask

What is difference between getchar and putchar?

getchar() function reads a character from the screen and returns it's ASCII value. This function reads only single character at a time. putchar() function puts the passed character on the screen and returns the ASCII value of the character. This function puts only single character at a time.

What is difference between getch and scanf?

The main difference between them is: scanf() reads input until it encounters whitespace, newline or End Of File(EOF) whereas gets() reads input until it encounters newline or End Of File(EOF), gets() does not stop reading input when it encounters whitespace instead it takes whitespace as a string.

What is the use of getchar ()?

getchar is a function in C programming language that reads a single character from the standard input stream stdin, regardless of what it is, and returns it to the program. It is specified in ANSI-C and is the most basic input function in C. It is included in the stdio. h header file.

Can we use Getchar instead of getch?

Both function can be used to read a character from standard input and they return an integer value (ASCII value). When we use getchar() then during execution the program waits for enter to be pressed. When we use getch() then entered value is returned immediately without waiting for enter key to be pressed.


1 Answers

getchar() is a standard function that gets a character from the stdin.

getch() is non-standard. It gets a character from the keyboard (which may be different from stdin) and does not echo it.

like image 114
Roy Dictus Avatar answered Oct 05 '22 23:10

Roy Dictus