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 can properly include . C or . CPP files into other source files.
The answer to the above is yes. header files are simply files in which you can declare your own functions that you can use in your main program or these can be used while writing large C programs. NOTE:Header files generally contain definitions of data types, function prototypes and C preprocessor commands.
Use double quotes #include "ClasseAusiliaria.c"
[Don't use angle brackets (< >
) ]
And I prefer to save the file with .h
extension In the same directory/folder.
TLDR: Replace #include <ClasseAusiliaria.c>
with #include "ClasseAusiliaria.c"
Change your Main.c
like so
#include <stdlib.h> #include <stdio.h> #include "ClasseAusiliaria.h" int main(void) { int risultato; risultato = addizione(5,6); printf("%d\n",risultato); }
Create ClasseAusiliaria.h
like so
extern int addizione(int a, int b);
I then compiled and ran your code, I got an output of
11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With