473,378 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

header file reg

Hai,
I wrote two functions in separate files named fibonacci.c and factorial.c
Will you please let me know how to place those two functions in a header file named hai.h,so that i can use them in other c files?Thanks for your reply in advance.
Aug 27 '12 #1
1 1572
divideby0
131 128KB
in hai.h, declare the function prototypes.

Expand|Select|Wrap|Line Numbers
  1. #ifndef __MYHEADER_HAI__
  2. #define __MYHEADER_HAI__
  3.  
  4. void foo_1(void); // from fibonacci.c
  5. void foo_2(void); // from factorial.c
  6.  
  7. #endif
include the header in the source files

Expand|Select|Wrap|Line Numbers
  1. // fibonacci.c
  2.  
  3. #include "hai.h"
  4.  
  5. void foo_1(void) {
  6.    // definition
  7. }
Expand|Select|Wrap|Line Numbers
  1. // factorial.c
  2.  
  3. #include "hai.h"
  4.  
  5. void foo_2(void) {
  6.    // definition
  7. }
in the main source file

Expand|Select|Wrap|Line Numbers
  1. #include "hai.h"
  2.  
  3. int main(void) {
  4.    // do something with foo_1() and foo_2()
  5. }
compile the sources; for example
cl main.c fibonacci.c factorial.c

I usually have good luck with something like that.
Aug 28 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Newsgroup - Ann | last post by:
I have a library function like GetOptions( ..., struct net_arch_t netArch, ....) and put the declaration into a regular header file like getopt.h. But this function declaration also needs the...
2
by: trying_to_learn | last post by:
im in the primary stages of learning C++. The book im learning from says Dont use using namespace.. directive in header file However im trying to make the following header file.I need to include...
15
by: Kannan Goundan | last post by:
Maintaining a C++ header file can be painful. I want a way to automatically generate header files from the implementation file. Does anybody know of a program that does this? If not, I'd like...
3
by: Sujan Datta | last post by:
What are the possible effects of modifying an existing header file, which includes bunch of defines, function prototypes and some struct definitions. The structure of the header file looks...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
9
by: chat | last post by:
Hi, every body. I have 3 files like this: -------------------------------------------------------- file name : header.h #ifndef TEST_H #define TEST_H int a=1; double b=0.5;
11
by: Gary Wessle | last post by:
Hi is it right to have a line like #include <path/to/header.hfor a library on my system, in my header file and use some functions provided by this library in the implementation file (file.cpp)...
7
by: The Cool Giraffe | last post by:
Please note that i do intend to use a header file. However, i'm not sure if it's really needed or just a convention. Suppose we have the following two files. // Something.h class Something {...
6
by: bobby | last post by:
hi group, Does the header file size or number in include(s) effect the size of executable file? In other world if i chose a large header file and include it with my source file does it increase...
6
by: Ramon | last post by:
Is there a way to initialize the variables (or other data) of a header file by using a function (similar to main() function)?? Thankx
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.