【发布时间】: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;使用指针。