Saturday, 22 September 2012

How to create your own header file in ‘C’

Here we have three files

1
. demo.h includes the header file and function declaration
2. demo.c includes the function definition
3. main.c includes the header to call function and function call

demo.h

#ifndef DEMO_H_   /* Include guard */
#define DEMO_H_

int functiontest(int x);  /* An example function declaration */

#endif
__________________________________________________________________

demo.c

#include "demo.h"  /* Include the header (not strictly necessary here) */

int functiontest(int x)    /* Function definition */
{
    return x + 5;
}
___________________________________________________________________

main.c

#include <stdio.h>
#include "demo.h"  /* Include the header here, to obtain the function declaration */

int main(void)
{
    int y = functiontest(4);  /* Function call */
    printf("%d\n", y);
    return 0;
}

1 comment:

  1. my friend it really works...... i like ur blog so much. It provide very useful information........

    ReplyDelete

Thanks for visiting...

How to access the files when Windows is damage

  You Need An optical drive (CD,DVD or Blu-Ray) drive on the computer you wish to repair. An  burning capable  optical drive on your working...