2014-12-06 13 views
0

我正在編寫一個C語言程序,其中一個模擬程序在Ubuntu 13.04環境下的一個理髮店一個椅子模型。得到的時間在Ubuntu的存儲大小

我有一個計時器()函數,這給了我這個錯誤:

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

這裏的功能和指令,稱之爲:

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

功能:

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()); 

5月的問題是:

1 - 那是什麼錯誤主要?

2-我該如何解決這個錯誤?

+3

閱讀*仔細* [時間(7)](HTTP ://man7.org/linux/man-pages/man7/time.7.html),[clock_gettime(2)](http://man7.org/linux/man-pages/man2/clock_gettime.2.html ),[localtime(3)](http://man7.org/linux/man-pages/man3/localtime.3.html),[strftime(3)](http://man7.org/linux/man -pages/man3/strftime.3.html),[random(4)](http://man7.org/linux/man-pages/man4/random.4.html)...沒有標準的'struct時間! – 2014-12-06 17:05:55

回答

0

如果你是在Ubuntu,你可以這樣做:

srand(time(NULL)); 

你不需要自己timer()功能。如果您需要比1秒更好的分辨率,請查看gettimeofday