【发布时间】:2021-06-30 19:06:41
【问题描述】:
首先是代码,
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
void printAttributes(de->d_name, &statBuff);
int main(){
struct stat{
} statBuff;
int err;
struct dirent *de;
DIR *dr = opendir(".");
if (dr == NULL) {
printf("Could not open current directory");
return 0;
}
while ((de = readdir(dr)) != NULL){
err = stat(de->d_name, &statBuff);
printf("%s\n", de->d_name);
if(err == -1){
printf("Error in Stat\n");
printf("Press 'Enter' to continue\n");
getChar();
return 1;
}
printAttributes(de->d_name, &statBuff);
}
closedir(dr);
return 0;
}
void printAttributes(de->d_name, &statBuff){
//function bs here
}
编译器说错误发生在第 8 行和第 43 行,这显然让我相信函数原型/调用有问题,但我无法弄清楚它是什么。任何帮助将不胜感激。
【问题讨论】:
-
struct stat{ } statBuff;这是一个很小的结构。 -
我认为你必须更好地理解如何将参数传递给函数,你不能在
void printAttributes(de->d_name, &statBuff);中传递de->d_name但应该是void printAttributes(typeof name, typeof *stat);