gpt4 book ai didi

c - 你如何在 C 中创建一个 "waits"和 x 秒数的函数?

转载 作者:太空宇宙 更新时间:2023-11-04 06:47:26 25 4
gpt4 key购买 nike

我试图让终端在屏幕上打印内容之前等待 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 上有一个“ sleep ”函数

#include <unistd.h>

//something your code

sleep(seconds);

希望对你有帮助

关于c - 你如何在 C 中创建一个 "waits"和 x 秒数的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56158798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com