Post

Header File Libraries In C

Header File Libraries In C

Header File Libraries

A header file in C is a file that contains function declarations, macros, and definitions. It helps you use built-in functions without writing them yourself.

💡 Think of a header file like a toolbox—it gives you ready-made tools (functions) so you don’t have to build them from scratch.

Common C Header Files & Their Uses

Header FileWhat It Does
<stdio.h>Input & output (e.g.,printf, scanf)
<stdlib.h>Memory management (malloc, free), conversions
<string.h>String handling (strlen, strcpy, strcmp)
<math.h>Math operations (sqrt, pow, sin, cos)
<ctype.h>Character handling (toupper, isdigit)
<time.h>Date & time functions (time, clock)
<stdbool.h>Boolean values (true, false)

Making A Custom Header File Libraries

Create a file named myheader.h

1
2
3
4
5
6
7
#ifndef MYHEADER_H  // This makes sure the spellbook isn't loaded twice
#define MYHEADER_H

void sayHello();  // Just telling the program: "I have a spell called sayHello!"

#endif

Create another file named myheader.c

1
2
3
4
5
6
#include <stdio.h>   // We need this to use printf
#include "myheader.h"  // Import the spellbook

void sayHello() {
    printf("Hello! I am your magic spell!\n");
}

Create a third file named main.c

1
2
3
4
5
6
7
#include <stdio.h>
#include "myheader.h"  // Load the spellbook!

int main() {
    sayHello();  // Use the magic spell
    return 0;
}

Run this in the terminal:

1
2
gcc main.c myheader.c -o main
./main
This post is licensed under CC BY 4.0 by the author.