C:带函数的结构声明.存储大小未知

I15*_*159 4 c struct function

关于使用函数的问题struct.我从R.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";             
Run Code Online (Sandbox Code Playgroud)

当我编译我的代码时,我遇到了一个错误:

type.c: In function ‘main’:
type.c:9:15: error: storage size of ‘buf’ isn’t known
Run Code Online (Sandbox Code Playgroud)

结构声明有什么问题?我应该明确声明结构大小吗?如果是,我怎么知道呢?主要问题 - 它是如何运作的struct method name

小智 8

你忘了包括:

   #include <sys/types.h>
   #include <sys/stat.h>
Run Code Online (Sandbox Code Playgroud)