Thread: how to create own header file

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    17

    how to create own header file

    please tell me how to create own header files.Can someone tell me with a small example

  2. #2
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    text editor

    man... ppl are so lazy to google these days...

  3. #3
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71
    You write them and then you save them as .h extension files. then you include them this way
    Code:
    #include "my_header.h"

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Any good IDE (I use Dev-C++) will allow you to create and save header files. They are like .cpp files except that they don't contain a main function. They are used to store variables, functions, and structures.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >They are like .cpp files except that they don't contain a main function.
    This works:
    Code:
    /* header.h */
    #include <stdio.h>
    
    int main ( void )
    {
      printf ( "Hello, world!\n" );
    
      return 0;
    }
    Code:
    /* main.c */
    #include "header.h"
    It's important to realize that headers are nothing more than a convenient way to organize text that's to be pasted into your code.
    My best code is written with the delete key.

  6. #6
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Prelude: I did know that, however a)I didn't want to confuse him (you won't usually see a header file with main) and b)I didn't really have another way to say it.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Class methods in header or source file?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2007, 05:23 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. When to create a header file?
    By jamie85 in forum C Programming
    Replies: 2
    Last Post: 03-20-2005, 11:57 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM