Thread: Program Organisation in multiple files

  1. #1
    Registered User
    Join Date
    Nov 2009

    Program Organisation in multiple files

    Suppose I want a program that uses a struct author. As I plan to make a big program, I want to organise it in different files:

    test.c will contain the main(), and will make use of the struct author

    author.h will contain the struct declaration and function declarations that work with author objects.

    author.c will contain the function implementations.

    So, the main file (test.c) will #include "author.h"

    My problem is that when I run this code, I won't work unless I put the struct declaration in both author.h and author.c:

    struct author {
        /*members go here*/
    typedef struct author author;
    What am I overlooking?
    Or is this the wrong way to organise a program?

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Did you include author.h on author.c as well?

  3. #3
    Registered User
    Join Date
    Nov 2009
    No I didn't and now I feel soooo stupid!

    Thanks, now it works with the struct declaration in author.h!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. header files and multiple files
    By Dedalus in forum C Programming
    Replies: 5
    Last Post: 06-16-2009, 09:21 AM
  2. Replies: 4
    Last Post: 07-24-2008, 09:02 AM
  3. WM_COPYDATA and mutex selecting multiple files
    By gh0st in forum Windows Programming
    Replies: 2
    Last Post: 10-27-2006, 02:22 PM
  4. Multiple source files for one program
    By gflores in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2004, 02:32 AM
  5. Replies: 1
    Last Post: 05-01-2003, 02:52 PM