我如何在 C 中加倍时间?

How do I double timeval in C?

我是 C 的新手,我有以下代码,我想将时间间隔加倍,我该怎么做?

#include <time.h>

struct timeval t ={1, 10000}; 

while(1){
    //some code to use timeval 
    Here I need to double the timeval. Meaning if the timeval was 1.1 seconds, I need to make t = 2.2
    seconds. 
}

您需要将微秒和秒加倍。

然后您需要检查微秒是否溢出(如果它大于一百万),在这种情况下您需要再增加一秒并从微秒中减去一“秒”。