谁能告诉我如何延迟或倒数c?我的意思是一秒钟后写1和2。我知道的唯一方法是
include<windows.h>
Sleep( 1000 /* milliseconds */ );
有人可以告诉我另一种方法吗? (我有Windows 8)
最佳答案
如果您仅限于标准C89
#include <stdio.h>
#include <time.h>
int main(void) {
time_t t;
/* wait until the Standard clock ticks */
t = time(0);
while (time(0) == t) /* void */;
/* print 1 */
puts("1");
/* wait until the Standard clock ticks again */
t = time(0);
while (time(0) == t) /* void */;
/* print 2 */
puts("2");
return 0;
}
如果可以使用POSIX:请使用nanosleep()。
关于c - 如何在C中延迟(backcount)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15189015/