PDA

Click to See Complete Forum and Search --> : Header Help


Help
Jan 13th, 2001, 01:42 AM
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

ExciteMouse
Jan 13th, 2001, 01:50 AM
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

Help
Jan 13th, 2001, 01:58 AM
Thanks ExciteMouse,
Works great :)

parksie
Jan 13th, 2001, 06:37 AM
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:

#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]

ExciteMouse
Jan 13th, 2001, 01:42 PM
so THATS what all that crap means!
i always wondered about that.