?
Solved

newbie header file question

Posted on 2003-02-18
3
Medium Priority
?
202 Views
Last Modified: 2010-04-15
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
Comment
Question by:deta_gen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
akshayxx earned 200 total points
ID: 7979842
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
 
LVL 20

Expert Comment

by:jmcg
ID: 10006276
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question