我编写了一个C控制台程序,用于在程序运行的任何时候检查按下的键。但是我每次都要按ENTER键来处理来自键盘的输入。如何在不必按ENTER键的情况下每次按下键?以下是我到目前为止的情况:
# include <stdio.h>
#include <stdlib.h>
#define RUNNING 1
int main()
{ printf("---------------------------------------------------------
-------------\n\n");
puts("Welcome to PUSH COUNTER appliction :)");
puts("Type any key to test here ...");
printf("---------------------------------------------------------
-------------\n\n");
while (RUNNING){
char c = getchar();
if(c != ' ') {
printf("Not a space button... Program listening for push button .\n\n");
}
else {
printf("Finally pressed a space bar. Updating counter now ...\n");
}
}
return(0);
}