How to access the fields of a timeval structure

后端 未结 4 557
说谎
说谎 2021-01-06 08:51

I\'m trying to print the values in a struct timeval variable as follows:

int main()  
{  

    struct timeval *cur;  
    do_gettimeofday(cur);          


        
4条回答
  •  清酒与你
    2021-01-06 09:12

    The variable cur is a pointer of type timeval. You need to have a timeval variable and pass it's address to the function. Something like:

    struct timeval cur;
    do_gettimeofday(&cur);
    

    You also need

    #include
    

    which has the definition of the struct timeval and declaration of the function do_gettimeofday.

    Alternatively you can use the gettimeofday function from sys/time.h.

    Working link

提交回复
热议问题