Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

newbie header file question

i have init(...), get_line(...), and equiv(...)

..of those, equiv returns a value...

i wrote the code, ..a file called program.c calls those functions from funcs.c.  But the teacher said we needed a .h file...how do i write one for those three functions...and also...do i include it in program.c or funcs.c or both?  thanks
0
deta_gen
Asked:
deta_gen
1 Solution
 
akshayxxCommented:
there are at least two ways to do it
one is to have one common header file. in which u make the declaration of ur function
and then include that header file both in prog.c and funcs.c

ONLY one of your program.c and func.c should have the final definition of the functions that are in func.c

another way is .. lets say u have a function
int f1(int){
//something
}
in func.c
and u want to use it in program.c
then in program.c  before u make the function call ( preferrably before main).
make a declaration like this
extern int f1(int);
------------------------
the header solution is like this
-----func.h------
#ifndef __FUNC_H
#define __FUNC_H
int f1(int);
//similar prototypes for other functions in func.c that u need to access in files outside func.c
#endif

------func.c------
#include "func.h"
+ all the same u have in ur func.c


-------program.c-------

#include "func.h"
+all the same like ur program.c



---------------------------



now if u have some function in program.c that u need in func.c
then make a header file program.h ( like above func.h) and include that file in func.c and
 in program.c (actually this is not that much needed )
0
 
jmcgOwnerCommented:
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by akshayxx.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now