如何将此程序从conio移植到curses?
我在Windows上写了这个简单的程序。因为Windows有conio,所以它工作得很好如何将此程序从conio移植到curses?,c,linux,ncurses,curses,conio,C,Linux,Ncurses,Curses,Conio,我在Windows上写了这个简单的程序。因为Windows有conio,所以它工作得很好 #include <stdio.h> #include <conio.h> int main() { char input; for(;;) { if(kbhit()) { input = getch(); printf("%c", input); }
#include <stdio.h>
#include <conio.h>
int main()
{
char input;
for(;;)
{
if(kbhit())
{
input = getch();
printf("%c", input);
}
}
}
#包括
#包括
int main()
{
字符输入;
对于(;;)
{
if(kbhit())
{
输入=getch();
printf(“%c”,输入);
}
}
}
现在我想把它移植到Linux,而curses/ncurses似乎是正确的方法。我如何使用这些库来代替conio来实现同样的功能
#include <stdio.h>
#include <ncurses.h>
int main(int argc, char *argv)
{
char input;
initscr(); // entering ncurses mode
raw(); // CTRL-C and others do not generate signals
noecho(); // pressed symbols wont be printed to screen
cbreak(); // disable line buffering
while (1) {
erase();
mvprintw(1,0, "Enter symbol, please");
input = getch();
mvprintw(2,0, "You have entered %c", input);
getch(); // press any key to continue
}
endwin(); // leaving ncurses mode
return 0;
}
您可以看到linux的kbhit()实现。谢谢,这正是我需要的。
gcc -g -o sample sample.c -L lncurses