sách gpt4 ai đã đi

bộ đếm thời gian - lập trình UNIX. struct timeval cách in nó (lập trình C)

In lại 作者:行者123 更新时间:2023-12-03 02:54:59 28 4
mua khóa gpt4 Nike

我正在尝试打印 timeval 类型的值。实际上我可以打印它,但我收到以下警告:

该行有多个标记

  • 格式“%ld”需要“long int”类型,但参数 2 的类型为“struct timeval”

程序编译并打印值,但我想知道我是否做错了什么。谢谢。

    printf("%ld.%6ld\n",usage.ru_stime);
printf("%ld.%6ld\n",usage.ru_utime);

其中的用法是类型

typedef struct{
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
}rusage;

struct rusage usage;

1 Câu trả lời

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.

所以你需要这样做

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

获得“格式良好”的时间戳,例如1.000123.

关于timer - UNIX 编程。 struct timeval 如何打印它(C 编程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1469495/

28 4 0
Bài viết được đề xuất: MongoDB 如何按字段值对数据进行分组
Bài viết được đề xuất: emacs - 符号的函数定义无效 : declare-function
Bài viết được đề xuất: bash - unix:循环查找命令的结果
Bài viết được đề xuất: visual-studio - 为整个解决方案运行自定义工具
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com