gpt4 book ai didi

c - 定时 C 程序循环

转载 作者:行者123 更新时间:2023-11-30 17:47:24 26 4
gpt4 key购买 nike

我需要根据用户输入(在 C 程序中)循环一定的时间。

示例:用户说循环 2 分钟(= 120 秒)。

while(time <= 2 Minutes)
{
do something
}

我该如何用 C 语言来做这件事?感谢您的帮助!!

最佳答案

如果您需要在特定时间内尽可能多次地执行某些操作,您可以使用 time() :

time_t secs = 120; // 2 minutes (can be retrieved from user's input)

time_t startTime = time(NULL);
while (time(NULL) - startTime < secs)
{
...
}

关于c - 定时 C 程序循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18936745/

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