www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/31/05:07:44

From: kunst AT prl DOT philips DOT nl
Subject: getch() on UNIX systems
To: mfeldman AT seas DOT gwu DOT edu
Date: Wed, 31 Aug 1994 09:42:59 +0100 (METDST)
Cc: roe2 AT midway DOT uchicago DOT edu, eliz AT is DOT elta DOT co DOT il,
djgpp AT sun DOT soe DOT clarkson DOT edu (DJGPP users list)

Michael Feldman (mfeldman AT seas DOT gwu DOT edu) writes:

> I'm preparing a C course, and am trying to get the stuff in the text
> to be as portable as possible, since the students have several compilers
> available.
> 
> (1) I'm trying to compile a program out of a book that uses "getch".
>     This should be in conio, which in djgpp just includes gppconio.
>     The program compiles but the linker reports that getch is undefined.
>     What is the magic to get the linker to find it?
> 
> (2) Just for curiosity, where is getch, etc., in standard (Unix) gcc?
>     The linker can't find it there either.
> 
> (3) What editor do most of you use with djgpp? EMACS? If so, where are
>     the DOS binaries? I could not find it in the usual place at WUSTL.
> 
> (4) Does gppconio read all the PC keystrokes (alt-keys, etc.)?
> 

Greg Roelofs (roe2 AT midway DOT uchicago DOT edu)
> getch() is a DOSism.

Eli Zaretskii (eliz AT is DOT elta DOT co DOT il)
> That's because there ain't no such thing as a Unix getch().


There is a 'getch' available on most Unix systems in the 'curses' library.
The 'curses' library is also available for PC (pdcurs21.zip).

The short program below runs on Unix as well as on PC (with 'curses').

------------------------------ getch.c ---------------------------------------
/* This is getch.c, compile with: gcc -o getch getch.c -lcurses */
#include <curses.h>
#define CTL_D   4

int main ()
{
  chtype c;

  initscr(); cbreak(); noecho();  
  while (1)
  {
    printw ("Enter a key (CTRL-D to quit) : "); refresh();
    c = getch();
    printw ("%d\n", c); refresh();
    if (c == CTL_D) break;
  }
  endwin();
  return 0;
}
------------------------------ getch.c ---------------------------------------

Pieter Kunst (kunst AT prl DOT philips DOT nl)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019