Getting time in ubuntu

Posted by user2578666 on Ask Ubuntu See other posts from Ask Ubuntu or by user2578666
Published on 2014-06-13T09:24:31Z Indexed on 2014/06/13 9:41 UTC
Read the original article Hit count: 1148

Filed under:
|

include

#include <stdio.h>


int GetTime()
{

   struct timespec tsp;

   clock_gettime(CLOCK_REALTIME, &tsp);   //Call clock_gettime to fill tsp

   fprintf(stdout, "time=%d.%d\n", tsp.tv_sec, tsp.tv_nsec);

   fflush(stdout);

}

I am trying to compile the above code but it keeps throwing the error:

time.c: In function ‘GetTime’:
time.c:12:4: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
time.c:12:18: error: ‘CLOCK_REALTIME’ undeclared (first use in this function)
time.c:12:18: note: each undeclared identifier is reported only once for each function it appears in
time.c:14:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘__time_t’ [-Wformat]
time.c:14:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long int’ [-Wformat]

I have tried compiling with -lrt flag and -std=gnu99. Nothing works.

© Ask Ubuntu or respective owner

Related posts about 12.04

Related posts about c