gpt4 book ai didi

c - C中的延迟()问题

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

尽管我为每个打印语句设置了不同的 Sleep() 计时器,但它似乎只执行计时器最高的那个。需要一些帮助来解决这个问题。 TIA!

#include <stdio.h>
#include <windows.h>

void gotoxy(short int x, short int y);

int main()
{
int c = 1, d = 1, e, x, y, z, a;
srand ( time(NULL) );

for(a = 0; a <= 100; a++) {
x = rand() % 9 + 1;
y = rand() % 9 + 1;
z = rand() % 9 + 1;
gotoxy(5, 5);
Sleep(200); printf("%i", x);
gotoxy(8, 5);
Sleep(50); printf("%i", y);
gotoxy(11, 5);
Sleep(500); printf("%i", z);
}

return 0;
}

void gotoxy(short int x, short int y){
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

最佳答案

  1. 不要期望应用程序级 sleep() 的准确性太高 - 比如实现。通常他们的计时器很容易错过 10 毫秒。
  2. 根据 documentationSleep() 参数以毫秒为单位。所以很容易就不会注意到这样的停顿。尤其是没有那么准确的实现。

我的建议是增加时间间隔并进行检查。或记录当前挂钟时间。

关于c - C中的延迟()问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28394834/

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