|

楼主 |
发表于 2015-5-11 06:04:45
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h> //for rand(), srand()
- #include <time.h> //for clock(), rand(), srand()
- #define LIMIT 10
- #define NUMBER_LEN 5
- int main(int argc, char **argv)
- {
- int count = 0, input = 0;
- time_t nowtime = 0;
- //clock_t nowtime = 0;
- srand(time(NULL));//发现这个放在rand()开头就行, 不用在每次调用rand()时再调用一次
- printf("测试:按ctrl+c退出\n");
- while(1)
- {
- for(count = 0; count < NUMBER_LEN; count++ )//数字长度
- printf("%d ", rand()%LIMIT);//输出数字
- //这里停止一秒
- nowtime = clock();//记录下启动时时间
- while((clock() - nowtime) < CLOCKS_PER_SEC) continue;
- printf("\r");//把光标放到数数字最前面
- for(count = 0; count < NUMBER_LEN; count++)
- printf(" ");//打印一串空格把字符盖掉
- printf("\r");
- //这里停止一秒
- nowtime = clock();//记录下启动时时间
- while((clock() - nowtime) < CLOCKS_PER_SEC) continue;
- }
- return 0;
- }
- //程序在linux下无法通过, 很奇怪在win下正常运行,
- //看标准定义, clock()函数应是一样的才对
- //难道linux下的clock()与win下的不一样?!
复制代码
|
|