【问题标题】:C expected expression before struct error结构错误之前的 C 预期表达式
【发布时间】:2015-11-17 13:19:27
【问题描述】:

为什么我在 struct at static void print_abc(struct abc); 之前得到错误预期表达式;在主要功能?

struct abc{
int a;
int b;
int c;
};
static void print_abc(struct abc){
printf("&i &i &d",a,b,c);
}

int main(void){
static void print_abc(struct abc);
}

【问题讨论】:

  • static void print_abc(struct abc); 这不是你调用函数的方式。
  • 并且没有像 "&i &i &d" 这样的说明符,您在 printf 中使用它来打印 int 变量。
  • 以及如何调用函数? a,b,c 的值将在另一个函数中声明
  • print_abc() 的范围内也没有a, b, c
  • 您显然已经消除了对一般编程的一些误解(有些问题不仅与 C 相关)。我建议开始阅读 C 书籍或教程、课程等。

标签: c struct


【解决方案1】:

1

关键字static是关键字,在尝试调用标有static的函数时不需要添加。请参阅this 了解更多信息。

2

您也不能将结构隐式转换为另一种数据类型。您正试图在 print_abc 函数中执行此操作。您需要显式访问成员变量。

3

&i 和 &d 不是在使用 printf 函数时插入整数的有效占位符。请改用 %d,有关详细信息,请参阅 this

代码应该是:

struct abc{
int a;
int b;
int c;
};
static void print_abc(struct abc){
printf("%d %d %d",abc.a,abc.b,abc.c);
}

int main(void){
void print_abc(struct abc);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-06
    • 2014-02-22
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多