刚入门C语言,
在编写一个倒计时程序,
运行在Mac系统下的VScode,
为什么我点运行,倒计时数字并没有按照预期每隔一秒闪一下,
而是在3秒钟后一起出现呢?
是我写的代码有错误,还是其他问题?
#include
#include
#include
int main()
{
int a;
a=3;
while(a>=0)
{
system("clear");
printf("%d",a);
sleep(1);
a=a-1;
}
return 0;
}
是不是clear不支持
改动处见注释,供参考:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int a;
a = 3;
while (a >= 0)
{
system("cls"); //system("clear"); 清屏 cls
printf("%d", a);
sleep(200); //sleep(1); 1毫秒时间太短了
a = a - 1;
}
return 0;
}