[英]How do you make a function that “waits” an x amount of seconds in C?
我试图使终端在屏幕上打印某些内容之前等待x秒钟。 我从网上从其他地方复制了代码,但是我的终端根本不等待任何时间,而是像往常一样完全执行所有操作。 你们知道为什么会这样吗?
for(int i = 0; i < 5; i++){
delay(5);
printf(". ");
}
void delay(int number_of_seconds)
{
// Converting time into milli_seconds
int milli_seconds = 1000 * number_of_seconds;
// Stroing start time
clock_t start_time = clock();
// looping till required time is not acheived
while (clock() < start_time + milli_seconds)
;
}
unistd.h上有一个“睡眠”功能
#include <unistd.h>
//something your code
sleep(seconds);
希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.