#include
This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation).
#include "file"
This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for . You can prepend directories to the list of quote directories with the -iquote option
C header file is a text file that contains pieces of code written in C programming language syntax, and whose name, by convention, ends with “.h” extension. A C header file ( also informally known as “.h file” pronounced dot-H-file ), is used inside a program by coding the “#include” preprocessor directive. The syntax is as follows:
#include
or
#include "user-defined-header-file"
Note the slight difference in the syntax when including a standard library header files and user defined header files.
Examples:
Imagine you are writing a program to convert a measurement in Miles to Kilometers. In order to accomplish this task, you write a function that does the job. Further assume that your implementation of the function is as follows:
ProgramA.c:
const double FACTOR = 1.609344;
double cvtMileToKilom( double miles );
int main()
{
double miles = 0;
printf("Enter measurement in Miles:");
scanf("%lf", &miles);
printf("%f miles is %f kilometers.\n", miles, cvtMileToKilom( miles ) );
return 0;
}
double cvtMileToKilom( double miles )
{
return FACTOR * miles;
}
A few days later you decide to write a program that converts miles to meters. Further assume that you love your previously written code, and you must reuse it for your new project. You have two options. One option is to copy your code and paste it into your new program, like the following:
ProgramB.c
const double FACTOR = 1.609344;
double cvtMileToKilom( double miles );
double cvtMileToMeter( double miles );
int main(void)
{
double miles = 0;
printf("Enter measurement in Miles:");
scanf("%lf", &miles);
printf("%f miles is %f meters.\n", miles, cvtMileToMeter( miles ) );
return 0;
}
double cvtMileToKilom( double miles )
{
return FACTOR * miles;
}
double cvtMileToMeter( double miles )
{
return cvtMileToKilom( miles ) * 1000;
}
Another, better, option is to separate your function declaration for cvtMileToKilom from its implementation. Suppose in your first project you structured your program as follows:
programA.h
const static double FACTOR = 1.609344;
double cvtMileToKilom( double miles );
programA.c
#include "programA.h"
double cvtMileToKilom( double miles )
{
return FACTOR * miles;
}
This way all you need to do for your new project is to include your header file, in your new program, and compile all your .c files:
programB.c
#include "programA.h"
#include
double cvtMileToMeter( double miles );
int main()
{
double miles = 0;
printf("Enter measurement in Miles:");
scanf("%lf", &miles);
printf("%f miles is %f meters.\n", miles, cvtMileToMeter( miles ) );
return 0;
}
double cvtMileToMeter( double miles )
{
return cvtMileToKilom( miles ) * 1000;
}
The beauty of this method is that you don’t have to remember how you implemented cvtMileToKilom. All you need to be able to do is to use it, and the #include “programA.h” statement is all you need to access your previous work. No need for copy pasting! This is the basic example of software reuse.
Please note that the code segments provided above are in no way the best way to do the projects. Nor are they examples of good C programming style. Rather they attempt to illustrate the use of header files. There is still a lot of room for improvement. For instance, you could put the function definitions of cvtMiletoMeter and cvtMiletoKilom in a single .c file, for example “conversion.c”. Also put the prototypes of these two functions in one .h file, for example “conversion.h”. This way, you can add more and more functions that convert from one unit to another. Every time you want to do another conversion, you can use your library and the functions available in it.
The idea of header files is not limited to C. For example, packages in Java are analogous to C header files.
2006-07-03 18:14:50
·
answer #1
·
answered by george 4
·
3⤊
0⤋
You use the angled brackets when the file is provided by the system and not the programmer (you), at least in C++. I think it's the same for C. This notation helps the source be system independent by eliminating the necessity of specifying a system-dependent path to standard headers.
2006-07-04 01:10:36
·
answer #2
·
answered by anonymous 7
·
0⤊
0⤋
if i remember right...
the angle brackets <> are given when a header file is a pre-defined c, c++ header file. I mean, the header file is installed while you install the c compiler.
The qoutes "" are provided when you are using a header file that is defined / created by you / user.
--x--
If that is not true, then i think the difference is that the qoutes are more prominent in the newer versions of c and c++, they no longer use <>.... however, i strongly think that my first explanation is probably more correct.
2006-07-04 01:04:36
·
answer #3
·
answered by Anonymous
·
0⤊
0⤋
If I remember my computer science correctly, the one in angle brackets (< >) is used when the file's location is within the program folder and the other one is used when the program will have to find the file first.
2006-07-04 01:04:57
·
answer #4
·
answered by Leon 5
·
0⤊
0⤋
the difference b/w <> and " " is simple in c.
if u use include statement in ur program, the compiler will searches the header file in current directoy and also in include directory path which u define in directories option. go through option >> directories.set ur include directory path in ur turbo c editor.
if u use "header file" statement in c program, compiler will searches the header files only in cuurent directory. it is useful when u create ur own header and save it only in project dir. this wiil reduce search time.
2006-07-04 02:26:46
·
answer #5
·
answered by ankur_parmar33 1
·
0⤊
0⤋