i created a header file named "pop.h" and saved in tc->include folder.......the codes included in header file is shown below

#include<stdio.h>
#include<conio.h>
int ssipower(int,int);
void main()
{
clrscr();
printf("power=%d",ssipower(3,3));
getch();
}
int ssipower(int a, int b)
{
int i,c=1;
for(i=1;i<=b;i++)
{
c=a*c;
return c;
}

when i tried to use this header file in a pgm im getting errors...the pgm shown as follows

#include<stdio.h>
#include<conio.h>
#include"pop.h"
void main()
{
printf("power=%d",ssipower(2,2));
getch();
}

cld anybody help me how to get solution for this......

Recommended Answers

All 3 Replies

i created a header file named "pop.h" and saved in tc->include folder.......the codes included in header file is shown below

#include<stdio.h>
#include<conio.h>
int ssipower(int,int);
void main()
{
clrscr();
printf("power=%d",ssipower(3,3));
getch();
}
int ssipower(int a, int b)
{
int i,c=1;
for(i=1;i<=b;i++)
{
c=a*c;
return c;
}

when i tried to use this header file in a pgm im getting errors...the pgm shown as follows

#include<stdio.h>
#include<conio.h>
#include"pop.h"
void main()
{
printf("power=%d",ssipower(2,2));
getch();
}

cld anybody help me how to get solution for this......

As far as I can remember, a c header file cannot contain implementation, only functions' signature. You declare your functions and constants in the header file. The implementation is done in that file which includes the header.

1) what are the errors -- or do we have to guess???

2) you have two main() functions declared. One in the header, where it should NOT be.

3) void main() -- don't use it. main() ALWAYS returns an int. Click here. for more info about that.

yeah, what CHASTER said:

the header file should only contain
(1) function prototypes
(2) defines
(3) macros

the functions themselves should be written in the *.c file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.