UNIX Programming. struct timeval how to print it (C-programming)

前端 未结 6 2023
慢半拍i
慢半拍i 2020-12-14 08:34

I am trying to print a value of type timeval. Actually I am able to print it, but I get the following warning:

Multiple markers at this line

  • format ‘%l
6条回答
  •  心在旅途
    2020-12-14 09:09

    In the GNU C Library, struct timeval:

    is declared in sys/time.h and has the following members:

    long int tv_sec
    

    This represents the number of whole seconds of elapsed time.

    long int tv_usec
    

    This is the rest of the elapsed time (a fraction of a second), represented as the number of microseconds. It is always less than one million.

    So you will need to do

    printf("%ld.%06ld\n", usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
    

    to get a "nicely formatted" timestamp like 1.000123.

提交回复
热议问题