At first you should realize that in the first code i is a variable.In the second part i is a function and it is wrong.What you wanted to write i think is
Code:
int multiply(int i)
{
printf("i * 2 = %d\n", (i * 2));
}
So what you want to do is having the file main.c and from function main call another function that is located at another file.So what you should do is having the file main.c .Then you have to create for example the file function.c and the function.h .At function.h only declarations must exist.Then you have to include the .h file at main in order for the main to know the existance of the function multiply.In code this is somehow like this
main.c
Code:
/*Now main can see what file functions.h contains.
*This is equivalent to have all the code of functions.h at this point
*of file instead of this line(#include "functions.h)*/
#include "functions.h"
int main(void)
{
int i=8;
mul(i);
return 0;
}
functions.h
Code:
/*DECLARATIION only*/
int mul(int i);
functions.c
Code:
#include <stdio.h>
int mul(int i)
{
printf("%d\n", i*2);
}
Happy to hear your questions