Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

getch()

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Gnome_KDE@Linux.deb

getch()

#1 Post by Gnome_KDE@Linux.deb »

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 ?

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#2 Post by lacek »

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.

Guest

#3 Post by Guest »

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 ..

Picard
Posts: 8
Joined: 2006-01-04 01:02

#4 Post by Picard »

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-Progra ... index.html

rohandhruva

#5 Post by rohandhruva »

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.

Post Reply