Created
October 7, 2019 08:45
-
-
Save tapin13/ca62c5740defef94156a94ddae879d72 to your computer and use it in GitHub Desktop.
Time delay in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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