Most definitely! What you're describing are header files. You can read more about this process here, but I'll outline the basics below.
You'll have your functions separated into a header file called functions.h
, which contains the following:
int return_ten();
Then you can have a functions.c
file which contains the definition of the function:
int return_ten()
{
return 10;
}
Then in your main.c
file you can include the functions.h
in the following way:
#include <stdio.h>
#include "functions.h"
int main(int argc, char *argv[])
{
printf("The number you're thinking of is %d\n", return_ten());
return 0;
}
This is assuming that your functions.h
file is in the same directory as your main.c
file.
Finally, when you want to compile this into your object file you need to link them together. Assuming you're using a command-line compiler, this just means adding the extra definition file onto the end. For the above code to work, you'd type the follow into your cmd: gcc main.c functions.c
which would produce an a.out file that you can run.