我正在开发一个C项目,我需要获取目录中的文件列表 . 我正在使用dirent.h但是在使用它时遇到了一些问题,我正在Linux下构建程序 .
当我尝试构建程序时,我收到以下错误
myClass:error: âDIRâ undeclared (first use in this function)
myClass:408: error: (Each undeclared identifier is reported only once
myClass:408: error: for each function it appears in.)
myClass:408: error: âdirâ undeclared (first use in this function)
myClass:410: warning: implicit declaration of function âopendirâ
myClass:413: warning: implicit declaration of function âreaddirâ
myClass:413: warning: assignment makes pointer from integer without a cast
myClass:415: error: dereferencing pointer to incomplete type
myClass:417: warning: implicit declaration of function âclosedirâ
下面是我正在使用的代码
int logMaintenance(void *arg)
{
DIR *dir;
struct dirent *ent;
dir = opendir(directory);
if (dir != NULL)
{
while ((ent = readdir (dir)) != NULL)
{
printf("%s\n", ent->d_name);
}
closedir(dir);
}
else
{
printf("Failed to read directory %i", EXIT_FAILURE);
}
return 0;
}
我不明白这些错误是什么意思,特别是当我说我已经包含了针对Liunux的dirent.h头文件时DIR是未声明的 .
谢谢你的帮助 .