In this article I am going to tell you the easiest way to
create your own header files in programming languages like C and C++. For this
you do not have to be an expert. This can be done by anyone who has just
started learning programming languages. Ok! Before starting the process let me
tell you the thing that why we need to create our own header files.
create your own header files in programming languages like C and C++. For this
you do not have to be an expert. This can be done by anyone who has just
started learning programming languages. Ok! Before starting the process let me
tell you the thing that why we need to create our own header files.
Why we need to create our own header files?
When we are working on big projects, we create many
functions to perform particular task. But this makes the source code very long.
So to solve this kind of problem we create a header file with all those
function and include this header file in our program. This makes the program
shorter, effective and easy to understand. Now I am sure that you understand
the purpose of creating our own header files.
functions to perform particular task. But this makes the source code very long.
So to solve this kind of problem we create a header file with all those
function and include this header file in our program. This makes the program
shorter, effective and easy to understand. Now I am sure that you understand
the purpose of creating our own header files.
Simple way to create your own header files in C/C++
1. Open notepad and write the function that you want to use
in your program. An example is shown below.
in your program. An example is shown below.
int sum(int a,int b)
{
return(a+b);
}
2. Now save the notepad file with .h extension. Like in above
example we are creating a function for sum, so save this file with name sum.h in
INCLUDE or BIN folder (you can use any other name).
example we are creating a function for sum, so save this file with name sum.h in
INCLUDE or BIN folder (you can use any other name).
3. After that write a program that uses this sum function and
include the header file that you have just created. I have written the program
below to make it easy to understand.
include the header file that you have just created. I have written the program
below to make it easy to understand.
#include<stdio.h>
#include<conio.h>
#include<sum.h> //header
file created by you
file created by you
void main()
{
int
a,b,s;
a,b,s;
clrscr();
printf(“Enter
the value of a and b:”);
the value of a and b:”);
scanf(“%d%d”,&a,&b);
s=sum(a,b);
printf(“Sum=%d”,s);
getch();
}
4. In this way you can add more functions to your header
file.
file.
Note: Do not use long header file name (about 7 to 8
characters), otherwise you will get an error. Write only the function
definition in the header file, there is no need to write function prototype.
characters), otherwise you will get an error. Write only the function
definition in the header file, there is no need to write function prototype.
If you have any kind of problem regarding the whole process
than feel free to ask by commenting below.
than feel free to ask by commenting below.
thx ^_^
This is not a good practice. You are allowed only to place prototypes in your header files and not the functions. If you add these things to your header file then there is absolutely no need for us to use linkers at all. Header files are used to import libraries that are, sometimes, pre-compiled.
I don't know how to study the allocation chapter in c and i would like to give the sequencial order so that i can under stand that part with ease……reply pls..
I am very poor in programming c so kindly give me tips for get ride of it ….
Just prefer a good book and start learning from basic. Do as much practice as you can. The main thing is to understand the logic. If you will be able to learn logic and start developing your own logic than you will not get any difficulty in learning any programming language.
So start your journey, i am always here to help you. If you will get any difficulty ask me i will try my best to help you.
READ LET US C BY YESHWANTH KANEETKAR
Read yeswant kanetkar “Let Us C”, “Pointer inC” and then read Dennis ritchie book. make practice problem from codechef ,SPOJ etc.
how to make my own library in borland c++?
or visual studio??? please help………..o.O
I will soon write article for this, keep visiting.
how to start implementing coding in visual basic
Did you ever learn visual basic?
sir …write a program in which if we enter number then it gives English word of that no.(eg. 5 = five )
Its simple bro.
#include
void main(){
int n;
printf(“Enter a number fromn 0 – 5 : “);
scanf(“%d”,&n);
if(n == 1)
printf(“%d = One”,n);
else if (n == 2)
printf(“%d = Two”,n);
else if (n == 3)
printf(“%d = Three”,n);
else if (n == 4)
printf(“%d = Four”,n);
else if (n == 5)
printf(“%d = Five”,n);
}
Add more ‘ else if ‘ statements to get desired results!
how many programming competitions you have won man
all your concepts are clear and you know advance programming too
u r superb
Thanks bro for your compliment. I have not participated in any big programming competition yet but I will participate soon.
I didn’t popped up with error. but I didn’t get any results.I did the code same as u mentioned above
i want to use myname.h instead of iostream.h
just type #include int the beginning of the notepad file for myname.h .
the u dont have to use iostream in your cpp file
Its very easy bro
U can change it in “header” folder in local disc C -turbo c++-bin-header
And u should rename tha iostream.h file bro
i want create a header file but i dont know proper use of linker so please give me advise sir
It is’nt working in TC++ and Code::Blocks, I’m 12-years-old and just learnt C. It is’nt working and can you teach me C++ and Java, i’D LIKE TO PURSUE THOSE FIELDS TOO! CAN YOU HELP ME?
plz give me any idea about programming thesis, what can i do…
its my final smester and submit the thesis…
plz give me any idea….
Thanx bro I have made my own header file
And how to save header file. When you’re working on Dev c++. Does it accepts ?
i refered to a old boo of 1998 and tried to make a header file using class but it showed error in inline decleration when i was compiling the prigram using the header file. the fault is in the header file accordind to the compiler.
help ME OUT?
After saving file to .h .
how to write the desired code for our header file.
I am facing problem, please help…….!!!!!
Please tell step by step process for all these….