Thread: Header Files

  1. #1
    Registered User
    Join Date
    Nov 2005

    Question Header Files

    I finished a project and a got a 48/50 on it but the points I lost where due to it being one day late and not making a header file. So now I am going back and trying to make a header file (for self satisfaction) and my question is how do I make and complie a header file with the program.... here is what I tried:

    I took the things my teacher wanted in the header, and placed them in a new file (hangman.h). This is what the file looks like:

    void menu(int *option);
    void players(int *player);
    void playGame(char word[], char list[][32], int player, int count, char usedWord
    void getList(char word[], char list[][32], int *count);
    void getWord(char word[], char list[][32], char usedWords[], int count);
    void enterWord(char word[]);
    void guessWord(char word[]);
    void drawMan(int numWrong);
    void listWrong(char wrongLetters[], int i, char guess);
    void listText(char wrongLetters[], int numWrong, char guess, char blanks[]);
    I then placed
    at the begining of my hangman.c file.

    I tried a few different complies but it didn't seem to work right.

    So how should I complie it? And is there a way to complie the header once, so you don't have to recomplie it? (So if you wanted to reuse the header, no extra compile time).

    (I believe my teacher said .:gcc project.c header.o -o project:. would add header.o to project.c and complie project.c. But how do you get header.h to header.o O o. Of course I could be a complete idiot and be way off... so if you aren't sure what I am talking about, but get the idea I don't either, let me know XD)

    (I have a class in ten minutes, and then work till three or four. So if I don't reply right away, I apologize ^^; )
    Last edited by Volair; 12-09-2005 at 10:36 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    You don't need to do any of that. You shouldn't anyway. Change the < > to " ", and put the header file in the same folder as your C file.

    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > But how do you get header.h to header.o

    The long way (you only compile what you need to)
    gcc -c hangman.c
    gcc -c project.c
    gcc -o project project.o hangman.o

    The -c option compiles the source into object files, but doesn't attempt to link the file with other object files or libraries.

    The short way (everything gets compiled every time)
    gcc -o project project.c hangman.c

    Naturally, this gets boring and error prone if you have lots of files, which is why people use makefiles later on to automate the process.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM