I have the following program for which i would like to add a timer in such a way that the time limit in between entering each number should be limited to 5 seconds.
int main()
{
int *arr = (int *)malloc(sizeof(int) * 5);
printf("Input 5 numbers: ");
for (int i = 0; i < 5; i++)
scanf("%d", &arr[i]);
return 0;
}
For instance, if i input the following numbers:
1 2 3 4 5
What i am trying to say is that the max duration allowed between typing 1
and 2
is just 5 seconds and so on... If the time limit exceeds, the program should display a message and terminate!
I know there are a few timers in C questions out there, but none of them really helped, so it would be really appreciated if a working piece of code is provided for this scenario