I want to read every keystroke from a console application written in c under windows and linux immediately. Unfortunately the function gets(line) does only return a value, when the "enter/return" key is pressed. I'm looking for a function that returns immediately after a key has been pressed.
Currently my code looks something like this:
char cTmp[MAX_LINE];
char line[MAX_LINE];
while( gets(line) != NULL) {
sprintf(cTmp,"Characters entered: %c", line);
puts(cTmp);
}
You're probably looking for
getch()
. On Windows (at least VC++) it's declared in<conio.h>
. On Linux it's part of curses.I think you're looking for
getchar()
andputchar()
:The following code worked for me. Thank you for pointing me into to right direction. http://bytes.com/topic/c/answers/503640-getch-linux