Thread: creating header files and libs

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    creating header files and libs

    Can someone explain or point me to a tutorial on writing my own functions into a header file. tia
    Monday - what a way to spend a seventh of your life

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Okay lets say you want to make a header. Just make any file with the extension .h so it may look like this. Lets just say for simplicity you have some simple function declarations.

    test.h
    Code:
    #ifndef TEST_H // so we don't include multiple times
    #define TEST_H
    
    // Function Prototypes
    
    void PrintHello( void );
    int Add2Num( int n1, int n2 );
    
    #endif // we are done here..
    Then we must include the definitions for the functions we declared in the header somewhere..

    test.c
    Code:
    #include <stdio.h>
    #include "test.h"
    
    void PrintHello( void )
    {
      printf( "Hello" );
    }
    
    int Add2Num( int n1, int n2 )
    {
      int result = n1 + n2;
     
      return( result );
    }
    Thats pretty basic, if you want something more complicated let me know. So say you have a main.c all you have to do is #include "test.h" and start calling those functions. Also make sure test.c is part of your current project.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static variables and header files
    By drrngrvy in forum C++ Programming
    Replies: 8
    Last Post: 12-02-2006, 01:27 PM
  2. DirectX 9.0c header & libs
    By cfriend in forum Game Programming
    Replies: 2
    Last Post: 09-21-2005, 02:53 AM
  3. files
    By Raven Arkadon in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2005, 02:18 PM
  4. Missing header files and libraries with Borland
    By quagsire in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2003, 06:19 AM
  5. header files (.h) and dinamic linked librarys
    By whitenoise in forum Linux Programming
    Replies: 3
    Last Post: 05-18-2002, 01:32 AM