How can I exit from an infinite loop, when a key is pressed?
Currently I\'m using getch, but it will start blocking my loop as soon, as there is no more input to read.
// Include stdlib.h to execute exit function
int char ch;
int i;
clrscr();
void main(){
printf("Print 1 to 5 again and again");
while(1){
for(i=1;i<=5;i++)
printf("\n%d",i);
ch=getch();
if(ch=='Q')// Q for Quit
exit(0);
}//while loop ends here
getch();
}