Write a function that takes a double argument representing a desired time delay and then runs a loop until that amount of time has passed. - C Function

C examples for Function:Function Definition

Description

Write a function that takes a double argument representing a desired time delay and then runs a loop until that amount of time has passed.

Demo Code

#include <stdio.h>
#include <time.h>

void timeout(double time);

int main(void)
{
  double time;/*from  www  . ja va  2 s. c om*/

  printf("Enter desired time delay in seconds: ");
  while(scanf("%lf", &time) == 1)
  {
    puts("Starting.");
    timeout(time);
    printf("It is now %2f seconds later!\n", time);
    printf("Enter desired time delay in seconds: ");
  }
}

void timeout(double time){
  clock_t start, end;

  start = clock();

  while (((end = clock()) - start) /  (double) CLOCKS_PER_SEC < time)
    continue;

  return;
}

Related Tutorials