Programming

Make your own header file!(Wndows and Linux)

Windows:

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++.
steps:
1.File->New
2.Now type functions in it.

e.g.:
//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…

3.Now
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 stored.by default it will be in bin folder.while saving note down address.
and don’t get confuse in address….

4.now file->new
and type…
#include<stdio.h>
#include<MyHeader.h>/*if u stored in include folder otherwise give path of file.*/
void main()
{
printf(“%d”,add(12,21);
}

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):
“cat>sampleHeader.h
int add(int a,int b)
{
return a+b;
}
^z”
(^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]
#include<sampleHeader.h>

[non root]
#include</home/sam/My_Header/sampleHeader.h>

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!
Enjoy!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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