0

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......

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by jephthah
0

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.

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.