How can I define a C function in one file, then call it from another?

Sam H picture Sam H · Nov 24, 2010 · Viewed 50.4k times · Source

If I define a function in file func1.c, and I want to call it from file call.c. How can I accomplish this task?

Answer

David Thornley picture David Thornley · Nov 24, 2010

You would put a declaration for the function in the file func1.h, and add #include "func1.h" in call.c. Then you would compile or link func1.c and call.c together (details depend on which C system).