3

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).

BenMorel
  • 34,448
  • 50
  • 182
  • 322

2 Answers2

1

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.

jonsca
  • 10,218
  • 26
  • 54
  • 62
0

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!

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106
Chris
  • 3,619
  • 8
  • 44
  • 64
  • If you flag your post for a mod, they might be able to move this information back into your question. I'm not completely clear on what, if any, options you have to reclaim it as part of your account. – jonsca May 28 '11 at 17:32