I need to read the instance of a keypress from the keyboard in linux or unix. I have used getchar() for the dos based compilers but I cannot find an eqivalent for the g++ compiler.
Is there such a function or do I have to construct my own. If so how is this done?
The easy way is to say 'Press return to continue'. getchar is buffered and is waiting for a CR before you get anything. The difficult way is to play with ioctl. There are so many options with ioctl, I wouldn't know how to advise you on it. If you call
ioctl( 0, FIONREAD, &numAvailable)
numAvailable will tell you how many chars have been pressed.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.