【发布时间】:2012-05-09 08:20:48
【问题描述】:
我是一名新的 C 程序员,我想知道如何将 struct 传递给函数。我遇到了一个错误,无法找出正确的语法来做到这一点。这是它的代码......
结构:
struct student{
char firstname[30];
char surname[30];
};
struct student person;
呼叫:
addStudent(person);
原型:
void addStudent(struct student);
以及实际功能:
void addStudent(person)
{
return;
}
编译器错误:
第 21 行:警告:可疑标签声明:struct student
第 223 行:参数 #1 与原型不兼容:
【问题讨论】:
-
你在哪里声明你的结构?在您的实际实现文件中,您的
struct student { /* ... */ };代码在哪里?看起来它在错误的范围内(例如在您的main函数中声明或您尝试从...调用addStudent的任何函数... -
是的,它在我的功能范围内