c - 如何打印结构体timeVal

标签 c sockets unix gcc gcc-warning

我的代码中有这一行

`printf("Rcvd pkt from %s:%d at <%ld.%06ld>\n", inet_ntoa(servAddr.sin_addr),  ntohs(servAddr.sin_port), timeVal.tv_sec, timeVal.tv_usec);`

这是我在编译 gcc 时收到的警告

`cc1: warnings being treated as errors
`client12.c: In function ‘main’:
`client12.c:131: warning: format ‘%06ld’ expects type ‘long int’, but argument 5 has type ‘__darwin_suseconds_t’
`client12.c:131: warning: format ‘%06ld’ expects type ‘long int’, but argument 5 has type ‘__darwin_suseconds_t’

我做错了什么?

PS - 我已经包含了 time.hsys/time.h

最佳答案

将数字转换为正确的类型:

printf("Rcvd pkt from %s:%d at <%ld.%06ld>\n", inet_ntoa(servAddr.sin_addr),  ntohs(servAddr.sin_port), (long int)(timeVal.tv_sec), (long int)(timeVal.tv_usec));

关于c - 如何打印结构体timeVal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15468564/

相关文章:

sql - 运行 sql 文件而不打印其内容 POSTGRES

COM 引用计数

c - 如何在代码片段中查找 TLB 未命中数?

sockets - lua http.request 返回尝试索引全局 'http'(一个 nil 值)

networking - recvfrom 没有收到来自客户端的任何信息,但客户端正在发送信息

linux - 如何检查变量是否包含有效的 ip 地址

regex - 如何比较两个文件之间字段的特定部分

c - 在 C 中访问结构元素

c - memcpy 类似继承的结构 - 安全吗?

java - 使用 Swing GUI 的简单客户端-服务器程序