How would I reuse functions in C? I've tried simply sticking them in a #include <myfunctions.h> , but that didn't work... Any (complete) suggestions/links on how to do this? I googled some and found this:

The way to write a header file is:

int sum( int a, int b) ;

#include "functions.h"
int sum( int a, int b) {
return a+b ;

g++ -c functions.cpp -o functions.o

#include "functions.h"
main() {
cout << sum(1,2) << endl ;

compile and execute main:
g++ main.cpp functions.o -o main

How would I, obviously replacing g++ with gcc and *.cpp with *.c, do these steps in Code::Blocks?

Thanks in advance,

>How would I reuse functions in C?
The easiest way is to create a header file with the declarations and link to a .c file with the definitions. Download one of the libraries here for a good example of that technique. Using Code::Blocks all you have to do is add the two files to your project and build.

This article has been dead for over six months. Start a new discussion instead.