让输出的数字串只显示一秒钟怎么显示不出来?
c4droid吧
全部回复
仅看楼主
level 9
我想让这个程序输出的数字串存在一秒钟后删除,但这个数字串根本就不出现,在电脑上都会显示一秒钟,在c4上怎么不行?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int sequence_lenght=3;/*循环次数*/
time_t now=clock();/*读取当前时间*/
for (int i = 1; i <= sequence_lenght; i++)
printf("%d", rand() % 10); /*输出随机生成的0-9的数字 */
while(clock() - now < CLOCKS_PER_SEC)
; /* 当时间小于一秒时,一直执行空语句 */
printf("\r"); /* 移到这行的开始处 */
for (int i = 1; i <= sequence_lenght; i++)
printf(" "); /* 输出空格覆盖掉原来的数字串 */
return 0;
}
2016年12月31日 13点12分 1
level 9
有大神给个解吗?
2016年12月31日 14点12分 2
level 8
printf("%d",rand()%10);改成printf("%d\n",rand()%10);试试
2017年01月01日 00点01分 3
我试过,可以显示,但是无法达到我的目的。
2017年01月01日 03点01分
@我12345644444 无法显示一秒么?试试usleep();
2017年01月01日 07点01分
1