-
Struct errors
hi i am new to c programming, having issue ith struct.
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct = {
const char *name;
const char *species;
int teeth;
int age;
}fish;
void catalog(struct fish f)
{
printf("%s is a %s with %i teeth. He is %i\n", f.name, f.species, f.teeth, f.age);
}
int main ()
{
fish snappy = { "Snappy", "Piranha", 69, 14 };
catalog(snappy);
return 0;
}
But when i compile it, it gives me this error
Code:
fish.c:4:16: error: expected ‘{’ before ‘=’ token
fish.c:9:2: warning: data definition has no type or storage class [enabled by default]
fish.c:10:21: warning: ‘struct fish’ declared inside parameter list [enabled by default]
fish.c:10:21: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]
fish.c:10:26: error: parameter 1 (‘f’) has incomplete type
fish.c: In function ‘main’:
fish.c:17:15: error: expected ‘;’ before ‘snappy’
fish.c:18:11: error: ‘snappy’ undeclared (first use in this function)
fish.c:18:11: note: each undeclared identifier is reported only once for each function it appears in
-
-
Hello balushyno1,
1) Remove '=' from line 4
2) Remove 'struct' keyword from line 10, since you have already typedef structure as 'fish', so there is no need to use it again. Only "voidcatalog(fish f)" would be enough.
You can solve such errors easily by looking closely at the compile logs. Best of Luck.
Best Regards,
Jaspreet