ChrisAsl
ChrisAsl

Reputation:

expected declaration specifiers or ‘...’ before ‘FILE’

I am writing code in c.
I am declaring a FILE* fp at the main function (main.c).
We have other files at the project too.
So at a header file I am getting this error:
"expected declaration specifiers or ‘...’ before ‘FILE’ problem"
at this line:
void myfunct(argumenttype argument, FILE *fp);

What am I doing wrong?

Working in Linux(gedit+gcc).

Upvotes: 3

Views: 7086

Answers (2)

Chris
Chris

Reputation: 3698

argumenttype is a typedef'ed type of pointer to a struct.

typedef struct testStruct testptr;
void myfunct(testptr test, FILE *fp);

I have just included stdio.h at this header file. And it worked fine. So everywhere I use library dependant functions or typedef'ed types I must include the relevant library?

Thank you very much!

Upvotes: 0

jonsca
jonsca

Reputation: 10381

You must include the header before you use the typedef'd element, otherwise FILE means nothing to the compiler, and it doesn't know what it is looking at.

Upvotes: 1

Related Questions