Results 1 to 5 of 5

Thread: Header Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Okay,

    I just created a header file called "practice.h"
    All it contain is
    #define ERROR printf("\nError");

    Then I go back to my source file and #include <practice.h>
    but when I compile it cant locate it.
    All files are in the same directory.
    Any help.

    (New to C )

    Thanks

  2. #2
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78
    use this:

    #include "practice.h"

    when you enclose something in <> that means its going to look in your systems library, quotes means its going to look in the current directory

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Thanks ExciteMouse,
    Works great

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Quick note on creating header files.

    If you have another source file that also includes practice.h, then it will try and redefine ERROR. To prevent against this, all header files have a mechanism similar to this to make sure they're only included once by the compiler:
    Code:
    #ifndef __PRACTICE_H__
    #define __PRACTICE_H__
    
    /* Header contents */
    
    #endif // __PRACTICE_H__
    That last comment at the end isn't absolutely necessary, but it's good practice in preprocessor #if / #endif constructs to put them in, since they tend to contain large volumes of code.

    [Edited by parksie on 01-13-2001 at 07:40 AM]
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Lively Member ExciteMouse's Avatar
    Join Date
    Jul 2000
    Location
    Dallas, TX
    Posts
    78

    oh!

    so THATS what all that crap means!
    i always wondered about that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width