0

Hi All,

I am new to c programming.
I have mulptiple c files which uses the client.h
Currently I am using my header file in each and every place where my c code is placed.
Can I put it at one particular location and use it as #include<client.h> in my all c code?

Please help me where I should put my header file in case of Linux as my operating system.

Thanks

3
Contributors
3
Replies
15
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

Yes ... you can have a file to be included ... that is just a list of other file 'includes' ... that you need included. Make sure that you have 'unique guards' in the .h header files...

Note: you can NOT define the same thing after it has been previously define ... not allowed in C/C++ (like it is in Python ... where a name can be reused and bound to anything ... on the fly.)

#ifndef HEADER_FILE1_H
#define HEADER_FILE1_H

// ... ALL your declarations go here ...

#endif

These guards are to prevent the same header files ... (used/needed by various .cpp files, to be complied) ... to be included more than once.

Edited by David W: added more text

0

Some compilers complain if the include files you create are in quote or angle bracks

#include "client.h"

Use quotes if client.h is in the same folder as your *.c file(s)

#include <client.h>

Use angle brackets if client.h is in the compiler's include folder.

Edited by Ancient Dragon

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.