I am trying to compile my code and the error is in my ADT module .h file at this line:

void printList(FILE* out, ListRef L);

The precise error is "list.h:42: error: expected ‘)’ before ‘*’ token"

Everything seems fine to me with the rest of the program but my compiler does not that asterisk and I have been struggling to find a solution. Am I missing a definition? Any help would be greatly appreciated.

You are probably missing the definition of FILE which is in stdio.h

I already included it in my .c file but do I need to include it in my .h file somehow?

It needs to have been included before you head is included.

The compiler reads everything in the order it appears in the files. So it reads the c file when it gets to a #include it opens and reads that if it finds another #include it then opens and reads that* taking each statement in turn. It requires everything it needs to compile a statement to have been already defined in what it has already parsed.

* Actually the pre-processor reads all the files and creates 1 large intermediary file (which you can often get the compiler to output if you desire) which is read by the actual compiler in a single pass.


So I guess in you c file you include your own header before stdio.h, you can either

  1. Alter the order of the headers in you c file
  2. Include stdio.h into your header**

** header files are normally written to protect against double inclusion to allow this (i.e. many headers and C file might include the same header). Also some coding standards prohibit inclusion of headers into other headers but that is a matter of style.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.