Make your own header file!(Wndows and Linux)


Yes you can make your own headers in c and c++.
very simple way …
(In windows OS)
you need a c/c++ compiler to test it.
Now open turbo c++.
2.Now type functions in it.

//header file no. 1
int add(int a,int b) //function 1
return (a+b);

int sub(int a,int b) //function no. 2
return (a-b);

//add ur own functions…

File->Save as
Give name as Myheader.h
and save(I will recommend that save in Turboc3\include\).
note: You must know where the file is default it will be in bin folder.while saving note down address.
and don’t get confuse in address…. file->new
and type…
#include<MyHeader.h>/*if u stored in include folder otherwise give path of file.*/
void main()

In Linux:

In linux there is easy way through shell:
Now follow these commands.
1.You will need root privilages to embed your header into system.(There is way without root also)
So type in shell
“su”(note:Without quotes
enter the passward if asked.if you dont know password goto step2.

2.Now in Home make directory
“mkdir My_Header”
“cd My_Header”

3.Now create file(you can use editors like gedit here I’ve used cat command):
int add(int a,int b)
return a+b;
(^z means ctrl+z which is used to terminate command in this case cat command)

4.Now check your header files for errors just by watching it again
“cat sampleHeader.h”

5.[root]Now this step isfor root users to embed file in system.
“cp ./sampleHeader /usr/include”
(You can use “mv .. …” too)

6.[root]Check the header file if successfully copied or not
“ls /usr/include/sample*”(it will list files starting with sample)

Now you are ready.

7.Type c code and include this header files
[for root user who copied header in /usr/include do like this]

[non root]

You have to give complete path.
dont copy above path.First check your file’s path by checking its properties and theninclude that file.

any error occured check steps correctly.

Try Experiments!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s