linux 和windows vc6.0都能成功编译,但linux中运行结果不对为什么,该怎么处理
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 作为统计时间的函数. 此函数在不同平台是有差异的.
具体用什么你会研究出来的.
#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 作为统计时间的函数. 此函数在不同平台是有差异的.
具体用什么你会研究出来的.