Create your own C Header file

See the following simple example to learn: (tested in gcc)
File 1: myLib.c
int sum(int a, int b)
{
      return a+b;
}
File 2: myLib.h
int sum(int, int);
File 3: testLib.c
#include<stdio.h>
#include"myLib.h"
int main()
{
      printf("%d\n",sum(10,20));
      return 0;
}
Commands to run:
gcc myLib.h myLib.c testLib.c
./a.out

No comments:

Post a Comment