I've looked around teh world and I stumbled on this code here, but I want to beable to make this loop printf the a++ postincrement while at the same time reading to see if a key has been pressed, if your familiar with qbasic, where you put n$ = inkey$ in a loop and it performs that loop w/o any type of pause until a desired key has been pushed. So this getchar waits for me to press a key, and once I press a key it prints a++, but I just want it to print a++ continiously while i can at the same time send/read keystrokes in the program, so im kinda like tryin to understand the concept of multithreading it....
I was looking at the NCURSES, but not sure if that does something similar or if there are any other approaches, dankeshen, and a good night. BTW This is being compiled on a FreeBSD 5.4, with gcc (GCC) 3.4.2 [FreeBSD] 20040728
here is the code:
Code:#include <curses.h> #include <stdio.h> #include <termios.h> #include <unistd.h> int main(void) { struct termios oldt, newt; int ch,a=0; while(1) { a++; printf("%d\n", a); // i want this to keep printing but i still want some type of getchar // not pausing the arithmetic tcgetattr( STDIN_FILENO, &oldt ); newt = oldt; newt.c_lflag &= ~( ICANON | ECHO ); tcsetattr( STDIN_FILENO, TCSANOW, &newt ); ch= getchar(); // this here pauses so a++ wont print continiously ;( tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); printf("%c",ch); } return ch; }



LinkBack URL
About LinkBacks


