Skip to content

Instantly share code, notes, and snippets.

@tapin13
Created October 7, 2019 08:45
Show Gist options
  • Save tapin13/ca62c5740defef94156a94ddae879d72 to your computer and use it in GitHub Desktop.
Save tapin13/ca62c5740defef94156a94ddae879d72 to your computer and use it in GitHub Desktop.
Time delay in C
#include <stdio.h>
#include <time.h>
void delay(int number_of_seconds) {
int milli_seconds = CLOCKS_PER_SEC * number_of_seconds;
clock_t start_time = clock();
while (clock() < start_time + milli_seconds) {}
}
int main() {
int i;
for (i = 0; i < 10; i++) {
delay(1);
printf("%d seconds have passed\n", i + 1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment