X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fbeginners.git;a=blobdiff_plain;f=time-example.c;fp=time-example.c;h=3fada4a83e6efb97181aaf31fedab469f816cd03;hp=0000000000000000000000000000000000000000;hb=00b7011a623e31d5cc5b4ae3dd720b029aa4da73;hpb=57186ae7db4905b7c9dcad2fd6cfa42e211f933d diff --git a/time-example.c b/time-example.c new file mode 100644 index 0000000..3fada4a --- /dev/null +++ b/time-example.c @@ -0,0 +1,37 @@ +/* + * example of gettimeofday usage + * + */ + +#include +#include +#include // only needed for time command (random seed) +#include + +int main(int argc,char **argv) { + + struct timeval foo1; + struct timeval foo2; + int sec,usec; + int i; + + srand(time(NULL)); // random seed + + printf("time 1:\n"); + gettimeofday(&foo1,NULL); + printf("seconds: %d \t usec: %d\n",(int)foo1.tv_sec,(int)foo1.tv_usec); + + while(i