I’m a new C programmer and I wanted to know how I can pass a struct through to a function. I’m getting an error and can’t figure out the correct syntax to do it. Here is the code for it….
Struct:
struct student{
char firstname[30];
char surname[30];
};
struct student person;
Call:
addStudent(person);
Prototype:
void addStudent(struct student);
and the actual function:
void addStudent(person)
{
return;
}
Compiler errors:
line 21: warning: dubious tag declaration: struct student
line 223: argument #1 is incompatible with prototype:
The line function implementation should be:
personis not a type but a variable, you cannot use it as the type of a function parameter.Also, make sure your struct is defined before the prototype of the function
addStudentas the prototype uses it.