2012-09-03 1 views
7

Windows에서이 간단한 프로그램을 작성했습니다. Windows에는 conio가 있기 때문에 정상적으로 작동합니다.이 프로그램을 conio에서 curses로 어떻게 옮깁니 까?

#include <stdio.h> 
#include <conio.h> 

int main() 
{ 
    char input; 

    for(;;) 
    { 
     if(kbhit()) 
     { 
      input = getch(); 
      printf("%c", input); 
     } 
    } 
}  

이제 리눅스로 포팅하고 싶습니다. curses/ncurses가 올바른 방법입니다. 어떻게하면 conio 대신에 라이브러리를 사용하여 동일한 작업을 수행 할 수 있습니까?

답변

9
#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; 
} 

here 당신은 리눅스에 대한 kbhit() 구현을 볼 수 있습니다.

+0

고마워, 그게 내가 필요한거야. –

+0

언제나 환영합니다. –

0

ncurses를 설치하고 <ncurses.h> 만 포함하십시오.

ncurses 설치 this은 도움이 될 것입니다.

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

와 gcc를 위해 ncurses를 lib 디렉토리 (-L lncurses) 플래그와 연결하는 것을 잊지 마세요 프로그램을 구축 할 때

+0

kbhit()가 존재하지 않는 것 같거나 잘못된 것이 있습니까? –

+0

kbhit()가 ncurses에 구현되어 있는지 확실하지 않습니다. – Jeyaram

관련 문제