How do I port this program from conio to curses?

戏子无情 提交于 2019-12-04 05:33:07
#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;
}

When building your program do not forget to link with ncurses lib (-L lncurses) flag to gcc

gcc -g -o sample sample.c -L lncurses

And here you can see kbhit() implementation for linux.

Install the ncurses and Just include <ncurses.h>.

for Installing ncurses this will be help-ful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!