getch()

Need help with C, C++, perl, python, etc?

getch()

Postby Gnome_KDE@Linux.deb » 2006-01-20 14:16

in anjuta c++ , Kdevelope c++ , gcc and g++ ..
when i use getch and include conio.h i find syntax errors .
in which header file can i find getch() or any function similar to it ?
Gnome_KDE@Linux.deb
 

Postby lacek » 2006-01-20 19:56

You have to use the ncurses library. Here is a dumb example:
Code: Select all
#include <curses.h>

int main() {
    int code;
   
    initscr();
    while (1) {
        code=getch();
        printf("Entered: %c\n\r",code);
    }
}

You have to link this code with the -lncurses switch.
See the manual page of ncurses for more info.
lacek
Moderator Team Member
 
Posts: 769
Joined: 2004-03-11 18:49
Location: Budapest, Hungary

Postby Guest » 2006-01-21 11:35

i tried it but the function initscr(); cleared all what was on the terminal , and after the program finished i couldn't write any thing on the terminal . so i have to close it and open it again ..
Guest
 

Postby Picard » 2006-01-21 14:04

well try this:
Code: Select all
#include <ncurses.h>

int main() {
  int c;
  initscr();
  raw();
  c = getch();
  printw("You have pressed: %c",c);
  getch(); //second time just to freez screen
  endwin();
  return 0;
}


and take a look at this:
http://en.tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html
Picard
 
Posts: 8
Joined: 2006-01-04 01:02

Postby rohandhruva » 2006-02-14 17:54

Or better yet, forget ncurses and all, just use getchar. It is a drop-in replacement to getch() , provided by all standard C++ compilers, including gcc.
rohandhruva
 


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable