I thought (upto now) that the function of getch() reads a character from input buffer (or keyboard, to be simple). But i had to argue with my lab instructor. They say that the only work of getch() is to hold the program execution. I know that getch() can be used that way. But i just wanted to know was it the real purpose it was invented? Or, Is it rarely used in getting one-character inputs?
getch
is used to “read a single-byte character from the terminal associated with the current window” as specified by POSIX. That is its primary function. It can be configured to be non-blocking (e.g. the function returns straight away if there is no input) so your lab instructor would be wrong to say that its only purpose is to pause program execution.
If you're talking about the getch()
implemented by Turbo-C then I'm not sure of the blocking semantics, but if its primary purpose was to pause program execution the function would surely be named something more apt, such as pause()
or waitkb()
or something similar.
Well as you know, getch() reads a single byte character from input.
In those great days of Turbo C compiler,
Common use of getch is that you can view the output (if any) of your program without having to open the output window if you are using turbo c compiler or if you are not running your program from command prompt
Ah, those were days!!
BTW getch is said to be deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With