I am working on a simple code that keeps incrementing a counter every second and will stop incrementing only when a 'q' is pressed .
I tried getchar() and getline() , but they require the user to enter an input for every loop .
to make it simpler , this code keeps counting on the console forever until I terminate it by ( Ctrl+c ) , I would like to use 'q' to do the same functionality.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int j=0;
int main()
{
printf("Enter Q to quit !\n");
while(1)
{
j++;
printf("%d\n",j);
Sleep(1000);
system("cls");
}
return 0;
}