davidd@wolf.cs.washington.edu (David Doll) (01/02/91)
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@wolf.cs.washington.edu
wirzeniu@cs.Helsinki.FI (Lars Wirzenius) (01/03/91)
In article <DAVIDD.91Jan1125815@wolf.cs.washington.edu> davidd@wolf.cs.washington.edu (David Doll) writes: >[about reading characters from the terminal without waiting for return] > ch=getchar(); Shouldn't you use getch instead of getchar if you're using curses? Also, check out #59 in the recently posted Frequently Asked Questions posting. Lars Wirzenius wirzeniu@cs.helsinki.fi wirzenius@cc.helsinki.fi