Header File Using GCC
CREATE HEADER FILE IN C USING GCC
Steps Are as Follows :
Step 1:-
Create a headeR file with .H extension .As you know Header Files Only Contain the Function Declarations:-
We will be creating swap.h with contents as-
extern void swap (int* a, int* b);
Step 2:-
Create Another File Named "swap.c" .We Will Be Writing The Function Body In this File -
void swap (int* a, int* b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
Step3:-
Now we will be writing our Main program .So Create A C file Named AS " Main.c" . We will be writing Here The Actual Code Implementation And Using Our Hand Made Header File.
#include "swap.h"
#include <stdio.h>
int main()
{
int a=1;
int b=2;
swap (&a,&b);
printf ("a=%d\n", a);
printf ("b=%d\n",b);
return 0;
}
#include <stdio.h>
int main()
{
int a=1;
int b=2;
swap (&a,&b);
printf ("a=%d\n", a);
printf ("b=%d\n",b);
return 0;
}
Step 4:-
Now We will be Compiling our whole source code
go to Terminal
# gcc -c Main.c swap.c .
Output will be Main.o and swap.o
Output will be Main.o and swap.o
#gcc -o Main Main.o swap.o
Output Will Be Main.exe or Main.o in windows or Ubuntu
Output Will Be Main.exe or Main.o in windows or Ubuntu
Open command Prompt or Terminal -Type Main.exe in windows or Main in ubuntu to see the Actual output
No comments: