i have this code and the user need to write a number in one second the problem is i dont know how to stop the scanf after one second,
for example : the user press enter to start a timer will start in the same time i want to break the while after one second the problem is scanf doesnt stop after 1 second
ps :it works when the user doesnt enter anything.
int i = 0;
int max = 0;
int num;
int counter = 0;
while (i != 10) {
char ch;
printf("Hit enter when ready\n");
fgetc(stdin);
scanf("%c", &ch);
if (ch == 0x0A || ch != 0x0A) {
num = -1;
DWORD start_time = GetTickCount();
DWORD check_time = start_time + 1000;
printf("ENTER KEY is pressed.\n");
while ((check_time > GetTickCount())) {
if (kbhit()) {
//fflush(stdin);
scanf("%d", &num);
break;
}
}
if (num == -1) {
printf(" :(\n");
} else {
printf("%d\n", num);
counter++;
if (num > max)
max = num;
}
}
i++;
}
printf("you entred %d numbers\n", counter);
printf("the biggest number is %d\n", max);
}```