My files are
// main.c
#include "add.c"
int main(void) {
int result = add(5,6);
printf("%d\n", result);
}
and
// add.c
int add(int a, int b) {
return a + b;
}
My files are
// main.c
#include "add.c"
int main(void) {
int result = add(5,6);
printf("%d\n", result);
}
and
// add.c
int add(int a, int b) {
return a + b;
}
you shouldn't include c-files in other c-files. Instead create a header file where the function is declared that you want to call. Like so: file ClasseAusiliaria.h:
In your Main.c file you can then include the newly created header file:
use
#include "ClasseAusiliaria.c"
[Dont use angle brackets (< >) ]and I prefer save file with
.h
extension in the same Directory/folder.#include "ClasseAusiliaria.h"
make a file
classAusiliaria.h
and in there provide your method signatures.Now instead of including the .c file include this .h file.
Change your
Main.c
like soCreate
ClasseAusiliaria.h
like soI then compiled and ran your code, I got an output of
You can include the .c files, no problem with it logically, but according to the standard to hide the implementation of the function but to provide the binaries, headers and source files techniques are used, where the headers are used to define the function signatures where as the source files have the implementation. When you sell your project to outside you just ship the headers and binaries(libs and dlls) so that you hide the main logic behind your function implementation.
Here the problem is you have to use "" instead of <> as you are including a file which is located inside the same directory to the file where the inclusion happens. It is common to both .c and .h files