Header files don't contain any algorithms themselves, they would only contain declarations, typedefs, global variables, etc.
So where do you put the algorithms themselves? you keep them in another .c file, which must be compiled and linked to your main file.
e.g. Lets say we have a function WriteUsage() that we want to place in a separate file and add it using a header file. We'll have 2 extra files (of course the file names are just examples):
1. writeusage.c
2. writeusage.h
Now, writeusage.c will contain the function body, and will look something like this:
Code:
#include "writeusage.h" //You don't need to include this header, however it is preferable since you can keep all the standard headers you need inside it
void WriteUsage(void)
{
printf("usage: program filename options\n");
}
writeuser.h will look like this:
Code:
#include <stdio.h>
void WriteUsage(void)
Your main file will look like something like this:
Code:
#include "writeusage.h"
int main(int argc, char *argv[])
{
...
if (something's wrong with the arguments)
{
WriteUsage();
do whatever you want
}
...
return 0;
}
Now when you want to compile it, you'll need to inform the compiler to compile wrtieusage.c, and the linker to link its object file to your program like this:
Code:
gcc main.c writeusage.c