Teen Programmers Unite  
 

 

Return to forum top

Header files

Posted by PavalDaniel [send private reply] at March 03, 2002, 01:09:48 PM

Does anyone know how to write a simple header file?
Is it enough to write:

printf("This is a program");

in a *.h file so that if you include it, the text is displyed on the screen when you run the program?

Posted by Psion [send private reply] at March 03, 2002, 01:12:30 PM

When you #include something, the text is just inserted as is. A "header file" is only valid when you insert it someplace where it would be valid if you just copied and pasted it there.

Posted by metamorphic [send private reply] at March 03, 2002, 02:00:13 PM

Also header files are most commonly used to hold function prototypes and class definitions. Normally code that preforms a task (as opposed to code that tells the compiler what a class or function does) such as your code above, would be placed in another .c or .cpp file and added to a project.

Posted by Mycroft [send private reply] at March 05, 2002, 06:57:42 PM

a header file includes preprocesser directives so basically every has the # in front of it. The most basic header would be to put all the #include <*.h> file you use in your program:

#include <stdio.h>
#include <windows.h>
ect.

Then you save it with a .h extension. Now instead of puting in all those includes in the .c or .cpp file just use your header.

I recommend you got to a place like www.gametutorials.com, they got a lot of basic information on using the #define, #if, ect. preprocessor statements. Headers are really cool you could basically write an entire program in it.

Posted by CodeRed [send private reply] at March 13, 2002, 11:39:37 AM

Umm... you can do that I guess... but the most common use is for function prototypes and class definitions, like metamorphic said.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.