Here are three different files. I am trying to add myfunc.h
, just as C Library header files are added to the program containing main
, so that functions present in the myfunc.h
can be called just by using #include<myfunc.h>
.
myfunc.c
float power(float p, float q)
{
float r,prod;
int i;
prod=p;
for(i=1;i<=q-1;i++)
prod=prod*p;
return prod;
}
char prime(int n)
{
int i;
for(i=2;i<=n-1;i++)
{
if(n%i==0)
return 'N';
}
if(n==i)
return 'Y';
}
myfunc.h
float power(float p, float q);
char prime(int n);
Practice.c
contains the main()
#include <stdio.h>
#include "myfunc.h"
main()
{
int i,k;
printf("\nEnter Number = ");
scanf("%d",&i);
k=prime(i);
printf("\n IS %d PRIME = %c",i,k);
}
Ques : 1 How do I use myfunc.c
& myfunc.h
in my main
program?
Ques : 2 I created & compiled myfunc.h
which in return produced myfunc.h.gch
file. What is this myfunc.h.gch
?
Consider Example
program.
#include <stdio.h>
main()
{
printf("This is an Example.");
}
Did I declare or define printf()
inside the main()
or anywhere? No, I just called it with value passed in it. But still the program gets compiled & executed successfully.
That's exactly how I want functions in myfunc.c
to be called. How can I do that?.