Read more about the C preprocessor (and also here). You often (and conventionally, so it is more a good habit than a requirement) would add a #include <stdio.h>
preprocessor include directive near the start of your translation unit (or near the start of your header file), i.e. your *.c
source file. Of course you need to include <stdio.h>
only in translation units using some standard I/O function (or name of a type like FILE
, or variable like stdout
). So you can avoid <stdio.h>
in modules unrelated to I/O, such as code doing only computations.
You certainly don't need to define one function per source file. It is common (and I even recommend it) to define several functions in one source file. In particular, you could declare static
some internal function and call it from another one (in the same translation unit).
You might want, with GCC, to have a single pre-compiled header (which practically has to include other ones), and you could decide to put all standard headers inclusions inside your header.h
. Read about include guards.
You could want to define (not only declare) some short static inline
functions in your header.h
, hoping that the compiler would inline most calls to them.
Your function.c
practically needs to #include <stdio.h>
because it is using printf
. If you miss that include you need to properly declare printf
.
BTW, if you compile with GCC, don't forget to enable all warnings & debug info, using gcc -Wall -Wextra -g
. And try once to get the preprocessed form using gcc -C -E function.c > function.i
then look with a pager (or an editor) into the generated function.i
. See also this.
Notice that Eclipse is not a compiler but an IDE, that is a glorified source code editor able to run other programs (like compilers, debuggers, etc...). Your compiler -started by Eclipse- is likely to be GCC (or Clang/LLVM).
Read also the Modern C book.
NB. Programming in C requires to define and follow many conventions, which could vary from one project to the next. But you'll better explicit them. I recommend to study the source code of some small or medium sized free software project (e.g. on github).