get the time under ubuntu storage size

2019-03-06 20:21发布

I'm writing a program in C-language which its a simulation program for one barbershop one chair model under Ubuntu 13.04 environment .

I have a timer () function which gives me this error :

storage size of ‘t’ isn’t known>>

here is the function and the instruction which call it :

  #include<time.h>
  #include<math.h>
  #include<stdlib.h>

the 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);
 }   

the instruction which call this function :

 srand((unsigned) timer());

may questions are :

1- what that's error main ?

2-how can I fix this error ?

标签: c time
2条回答
小情绪 Triste *
2楼-- · 2019-03-06 20:46

If you are on ubuntu, you can just do:

srand(time(NULL));

You don't need your own timer() function. If you need more fine resolution than 1 second, look into gettimeofday.

查看更多
Emotional °昔
3楼-- · 2019-03-06 20:57

You seem to be trying to run MS-DOS / Turbo-C code on Linux?

There's no struct time and gettime() function in the Unix C library, you're probably looking for struct tm and localtime() instead, see e.g.:

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

查看更多
登录 后发表回答