【发布时间】:2021-12-09 23:26:34
【问题描述】:
我想学习使用 utmp.h 附带的函数和数据结构。 在下面的代码中,我想遍历 utmp 结构并打印它们的数据字段。
#include <stdio.h>
#include <utmp.h>
int main()
{
struct utmp *data;
data = getutent();
int i = 0 ;
while(data != NULL)
{
++i;
printf("%s\n" , data->ut_id);
data = getutent();
}
printf("%d" , i);
return 0 ;
}
即使ut_id 是char[4] 类型,当我运行代码时,我也会收到以下警告:
警告:“__builtin_puts”参数 1 声明的属性“非字符串”[-Wstringop-overflow=]
我该如何解决?
【问题讨论】:
-
该字段可能不适用于以 0 结尾的 C 字符串,并且不应与期望为 0 的函数一起使用。
标签: c unix compiler-warnings gcc-warning