![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 16
| Header files Code: #include "functions.h" p.s. I'm using Borland C++ 3.1 Last edited by nowber; 11-11-2009 at 03:28 PM. |
| nowber is offline | |
| | #2 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Header files are actually not necessary at all, but if you want to use one, go ahead. Anyway, no, there should not be a main() in the .h file. Each program can have only one main(). A header is not intended to used by itself.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 16
| Ok, so I have a functions.h header file (without the main function) and a main.c file. If I add both of them to a project and run it, I get multiple errors saying: _function1 defined in module MAIN.C is duplicated in module FUNCTIONS.H _function2 defined in module MAIN.C is duplicated in module FUNCTIONS.H etc... although I have defined them ONLY in functions.h file. The same error is produced for the array of records, that I've defined in functions.h. Any idea of what I'm doing wrong? Here's a small example how it looks in general: Code: (functions.h)
int number (int low, int high);
struct rec {
char name[33];
};
struct rec arr[5]; // array of records
int number (int low, int high){
... some actions
}
(main.c)
#include "functions.h"
number(1,50)
Last edited by nowber; 11-11-2009 at 04:08 PM. |
| nowber is offline | |
| | #4 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| I am not familiar with the Borland compiler, so I presume this means you are doing something with the IDE? Anyway, normatively you just include the .h file in your .c file: Code: #include "myheader.h" Then you just compile the .c file and the .h file will be included. [edit] okay, it looks like that is what you are already doing....hmmm
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trying to make the best use of header files | alanb | C++ Programming | 4 | 08-31-2009 04:45 PM |
| what am I missing? (Program won't compile) | steals10304 | C Programming | 3 | 08-25-2009 03:01 PM |
| Header files and multiple definitions | sjweinberg | C++ Programming | 16 | 07-17-2009 05:59 PM |
| #include header files or .cpp files? | DoctorX | C++ Programming | 3 | 12-23-2006 12:21 PM |
| Request for comments | Prelude | A Brief History of Cprogramming.com | 15 | 01-02-2004 10:33 AM |