Header Files in C

Header Files in C


You can also use a folder structure for libraries:

#include "myfolder/myfile.h"

Let’s make an example. This program calculates the years since a given year:

#include 

int calculateAge(int year) {
  const int CURRENT_YEAR = 2020;
  return CURRENT_YEAR - year;
}

int main(void) {
  printf("%u", calculateAge(1983));
}

Suppose I want to move the calculateAge function to a separate file.

I create a calculate_age.c file:

int calculateAge(int year) {