【问题标题】:How do I solve the error "expected ')' before '->' token" in my code?如何解决我的代码中“->”令牌之前的错误“预期的')'?
【发布时间】: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-&gt;d_name, &amp;statBuff); 中传递 de-&gt;d_name 但应该是 void printAttributes(typeof name, typeof *stat);

标签: c file directory


【解决方案1】:

正如评论中提到的,您误解了函数定义、声明和调用之间的区别 看看这个:https://www.tutorialspoint.com/cprogramming/c_functions.htm

此外,作为调试您不理解的内容和寻求帮助的一般提示: 尝试使示例尽可能简短和简单。 我通常发现在简化的过程中,我找到了我要查找的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    相关资源
    最近更新 更多