Course contentsShow
← C
Lesson 379 of 1,2195. FunctionsFree lesson

Using `#include` with quotes

Using #include with quotes

What you'll learn: How to tell the C compiler to look for custom header files inside your own project folder instead of the system library.

The "Home Cooked" vs. "Store Bought" Analogy

Think of your C compiler as a chef. When you use <stdio.h>, you are using angle brackets. This tells the chef to look in the "Professional Pantry"—a specific folder on your computer where all the standard C tools live. These are the "store-bought" ingredients that come pre-installed with your compiler.

However, as your programs get bigger, you will start writing your own header files to organize your code. These aren't in the professional pantry; they are sitting right there in your project folder, like ingredients in your home kitchen. To tell the compiler to look in your current folder first, you swap the angle brackets for double quotes: #include "my_functions.h".

How the Search Works

When the preprocessor sees quotes, it follows a specific search order:

  1. Local Search: It looks in the same directory (folder) where your .c file is located.
  2. System Search: If it can't find the file locally, it then looks in the standard system libraries (the same place angle brackets look).

By contrast, using angle brackets < > skips the local search entirely and goes straight to the system folders. Using quotes is safer for your own files because it ensures the compiler doesn't accidentally grab a system file with a similar name.

Modularization in Action

Imagine you have a file named physics.h that contains your custom math formulas. To use it in your main program, your code would look like this:

#include <stdio.h>   // Search system libraries for standard I/O
#include "physics.h" // Search the project folder for custom formulas

int main() {
    // A function defined inside physics.h
    double force = calculate_gravity(10.0, 5.0);
    
    printf("The calculated force is: %f\n", force);
    return 0;
}

By using quotes, you’ve modularized your code. You can keep your complex logic in physics.h and keep your main.c file clean and readable.

Key takeaway

Use #include "filename.h" for files you created in your project folder, and #include <filename.h> for standard built-in libraries.