Can someone explain or point me to a tutorial on writing my own functions into a header file. tia
Can someone explain or point me to a tutorial on writing my own functions into a header file. tia
Monday - what a way to spend a seventh of your life
Okay lets say you want to make a header. Just make any file with the extension .h so it may look like this. Lets just say for simplicity you have some simple function declarations.
test.h
Then we must include the definitions for the functions we declared in the header somewhere..Code:#ifndef TEST_H // so we don't include multiple times #define TEST_H // Function Prototypes void PrintHello( void ); int Add2Num( int n1, int n2 ); #endif // we are done here..
test.c
Thats pretty basic, if you want something more complicated let me know. So say you have a main.c all you have to do is #include "test.h" and start calling those functions. Also make sure test.c is part of your current project.Code:#include <stdio.h> #include "test.h" void PrintHello( void ) { printf( "Hello" ); } int Add2Num( int n1, int n2 ) { int result = n1 + n2; return( result ); }
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers