首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

linux 和windows vc6.0都能成功编译,但linux中运行结果不对为什么,该怎么处理

2012-05-11 
linux 和windows vc6.0都能成功编译,但linux中运行结果不对为什么#includestdio.h#includetime.h#incl

linux 和windows vc6.0都能成功编译,但linux中运行结果不对为什么
#include<stdio.h>
#include<time.h>
#include<stdlib.h>

main()
{
int length = 2;
int counter = 0;
int i;
long now;


now = clock();
length += counter++ % 3 == 0;
for(i =1; i <= length; ++i)
printf("%d ", rand() % 10);
for( ;(clock() - now) < CLOCKS_PER_SEC; );

printf("\r");
for(i =1; i <=length; ++i)
printf(" ");
return 0;
}

[解决办法]
不要使用 clock 作为统计时间的函数. 此函数在不同平台是有差异的.
具体用什么你会研究出来的.

热点排行