关于使用struct
函数的问题。我从r.s stevens的书中摘录了一些片段,我看到了几次类似的片段。我建议获得一些C和Linux的经验,但我真的不知道如何在这种情况下正确地使用struct。
struct stat buf; // The error line
for (i=1; i < argc; i++){
if (lstat(argv[i], &buf) < 0) { // Usage of
err_ret("lstat error");
continue;
}
if (S_ISERG(buf.st_mode))
ptr = "regular";
当我编译我的代码,我有一个错误:
type.c: In function ‘main’:
type.c:9:15: error: storage size of ‘buf’ isn’t known
结构声明有什么问题?我应该显式声明结构的大小吗?如果是,我怎么知道?而主要的问题是——struct method name
是如何工作的?
你忘了包括:
#include <sys/types.h>
#include <sys/stat.h>