【问题标题】:storage size of DIR variable is not knownDIR 变量的存储大小未知
【发布时间】:2022-06-14 23:57:02
【问题描述】:

故障函数代码为:

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#define _ISDIR 1729
#define _ISFILE 431
#define _EXIST_ERR 611
#define _BUF_LEN 512
unsigned int fod(char*);
unsigned int fod(char *name){
    DIR check_dir;
    check_dir=opendir(name);
    int openf=open(name,O_RDONLY);
    if(check_dir!=NULL){
        return _ISDIR;
    }
    if(openf!=-1){
        return _ISFILE;
    }
    return _EXIST_ERR;
}

当我用 gcc 12.1.1 编译它时,我得到以下错误:

copy.c:14:9: error: storage size of ‘check_dir’ isn’t known
   14 |     DIR check_dir;
      |         ^~~~~~~~~

我该如何解决?函数参数是对的,大家都说目录应该这样打开。我该如何解决?

【问题讨论】:

  • 尝试DIR *check_dir;使用指针。

标签: c io


【解决方案1】:

它无法编译,因为DIR struct 不是固定的,您需要使用指针来代替。所以替换这个:

    DIR check_dir;

到这里:

    DIR *check_dir;

【讨论】:

    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 2022-07-08
    • 2019-06-30
    • 1970-01-01
    相关资源
    最近更新 更多