From the
getch() manual page:
Code:
NAME
getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or push back) characters
from curses terminal keyboard
SYNOPSIS
#include <curses.h>
int getch(void);
int wgetch(WINDOW *win);
int mvgetch(int y, int x);
int mvwgetch(WINDOW *win, int y, int x);
int ungetch(int ch);
int has_key(int ch);
You will find, in
The C Programming Language, both the fist and second editions, a demonstration of a
getch() function (on page 79 of, yup, both editions). Note that you would not actually use this function in practice, it's for illustration purposes only.
Code:
#include <stdio.h> /* needed for printf() */
#define BUFSIZE 100
char buf [BUFSIZE]; /* buffer for ungetch() */
int bufptr = 0; /* next free position in buf */
int getch (void) /* get a (possibly pushed back) character */
{
return (bufptr > 0) ? buf [--bufptr] : getchar ();
}
void ungetch (int c) /* push character back on input */
{
if (bufptr >= BUFSIZE)
printf ("ungetch: too many characters\n");
else
buf [bufptr++] = c;
return;
}
Hope this helps some.