summary of keyboard input solutions
David Doll
davidd at wolf.cs.washington.edu
Wed Jan 2 07:58:15 AEST 1991
Heres a sampling of the solutions I got. Thanks to all who reply'd and I hope
this helps somebody else.
============================================================
this was my orginal code...
#include <stdio.h>
#include <curses.h>
/*
to compile: cc -o run test.c -lcurses -ltermcap
*/
main()
{
int ch;
int i;
cbreak();
for (i=0; i<10; i++){
ch=getchar();
putchar(ch+1);
putchar('\n');
}
nocbreak();
}
the problem was doing some crunching and then get a user inputed value w/o
them having to hit a <cr>. The code above locked the keyboard up...
=====================================================================
main()
{
int ch;
int i;
initscr();
cbreak();
for (i=0; i<10; i++){
ch=getchar();
/* putchar(ch+1); */
}
nocbreak();
}
-----------
By adding the initscr(), the program stopped locking up. Then i removed the
putchar(ch+1) and it got rid of the garbage. Try it with the putchar and
some garbage seems to pop up all over the place, not sure as to why, but this
.....
==================================================================
My manual says: before you do anything call 'initscr()'.
After that say 'cbreak() ; nonl() ; noecho()'.
You will get input char by char, un-echoed.
Look at keypad() if you want arrow-keys etc.
=================================================================
>main()
>{
> int ch;
> int i;
> cbreak();
> for (i=0; i<10; i++){
> ch=getchar();
> putchar(ch+1);
> putchar('\n');
> }
> nocbreak();
>}
I think the problem is that you have not called the initialization
function for curses. I did that once, because the documentation
made it sound like you only needed to call it for the screen
routines.. after several core dumps, I figured it out. =^)
---------------
screen look like the new one. In order to initialize the
routines, the routine initscr() must be called before any of
the other routines that deal with windows and screens are
used. The routine endwin() should be called before exiting.
----------------
Doesn't mention anything about the keyboard DOES it? =^)
But I think initscr() might fix it.
==========================================================================
--
David Doll
Computer Science Dept.
University of Washington
Seattle, WA 98195
M/S: FR-35
davidd at wolf.cs.washington.edu
More information about the Comp.lang.c
mailing list