by temporary40 » Thu Jan 06, 2011 11:04 pm
To create header, you will need to create a H file and another corresponding C file.
1) From your main C file (where you put the main() function), include the H file.
For example
____________________________________________
|#include <function.h>
|int main()
|{
| //your main program here...
|}
|___________________________________________
2) Then in the function.h, you will need to have your function prototype. Remember to add the preprocessor (#ifndef, #define, #endif) so your compiler will compile it once only.
For example...
____________________________________________
|#ifndef FUNCTION
|#define FUNCTION
|int myfunc();
|int myfunc2();
|int myfunc3();
|
|#endif
|___________________________________________
3) Then, in the corresponding c file (function.c), include the the function.h and write the subroutine function (function definition).
____________________________________________
|int myfunc()
|{
| //code here
|}
|int myfunc2()
|{
| //code here
|}
|int myfunc3()
|{
| //code here
|}
|___________________________________________
4) You are allowed to create global variables in the function.c file
____________________________________________
|int value, value1 = 100, value2 = 200;
|___________________________________________
5) But if you want the variables to be accessed in other file (for example the main function), you need to 'extern' the variables in the function.h file
____________________________________________
|extern int value, value1, value2
|___________________________________________
This is basically sums it up...