-1

我对 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. 
}
4

1 回答 1

3

您需要将微秒和秒都加倍。

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

于 2020-12-14T23:51:45.027 回答