The point of this program is to print "Hello World" 1000 at a certain speed. The user can press 'f' key to speed up the print or 's' key to slow down the speed and 'x' key to end the program. I need to use getch() so that it does a non-blocking read form the keyboard. I've tried this, but I can't get my head around how getch() works...
#include<stdio.h>
#include<ncurses.h>
int main()
{
int speed = 5000000, i;
char keypress;
for (i=0; i<1000; i++)
{
printf("Hello World!\n");
keypress = getch();
switch(keypress)
{
case 'f':
speed+= 100000;
break;
case 's':
speed-= 100000;
break;
case 'x':
return;
break;
}
usleep(speed);
printf("__________________________________");
}
return 0;
}