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

前端 未结 6 2017
慢半拍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条回答
  •  Happy的楠姐
    2020-12-14 09:08

    Since struct timeval will be declared something like:

    struct timeval {
        time_t      tv_sec;
        suseconds_t tv_usec;
    }
    

    you need to get at the underlying fields:

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

提交回复
热议问题