0

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

Criss Hills
  • 189
  • 1
  • 12
  • Does this answer your question? [How to restrict input time limit in cin?](https://stackoverflow.com/questions/22818994/how-to-restrict-input-time-limit-in-cin) – Nick Reed Mar 18 '21 at 04:09
  • that's in c++, i am not rly sure how c++ syntax works and what are c++ equivalent header files in c. – Criss Hills Mar 18 '21 at 04:11
  • My mistake, I jumped the gun and mixed up the languages - how about [this one](https://stackoverflow.com/q/13551058/7431860)? – Nick Reed Mar 18 '21 at 04:13
  • ok thats actually pretty relevant. but dont close this qs yet, just want to make sure the question works and thx! – Criss Hills Mar 18 '21 at 04:15

0 Answers0