在ubuntu存储大小下获得时间

我正在用C语言编写一个程序,它是Ubuntu 13.04环境下一个理发店一个椅子模型的模拟程序。

我有一个timer()函数,它给了我这个错误:

storage size of 't' isn't known>>

这是函数和调用它的指令:

  #include #include #include 

function :

  long timer() { //get current system time struct time t; gettime(&t); //return number of hundred of second return(((long)3600*t.ti_hour+60*t.ti_min+t.ti_sec)*100+t.ti_hund); } 

调用此函数的指令:

  srand((unsigned) timer()); 

可能的问题是:

1-这是什么错误主要?

2 – 如何修复此错误?

你似乎试图在Linux上运行MS-DOS / Turbo-C代码?

在Unix C库中没有struct timegettime()函数,你可能正在寻找struct tmlocaltime() ,参见eg:

http://www.tutorialspoint.com/c_standard_library/c_function_localtime.htm

如果你在ubuntu上,你可以这样做:

 srand(time(NULL)); 

您不需要自己的timer()函数。 如果您需要比1秒更精细的分辨率,请查看gettimeofday