70 likes | 195 Views
ENEE150 Discussion #3 Week 2/10. Header Files. “.h” files Declares prototypes for 1 program #include “ backgammon.h ” Change the prototype in header file, changes the prototypes in all the respective files. Header Files. By convention: Don’t put actual implementation code in “.h” files
E N D
Header Files • “.h” files • Declares prototypes for 1 program • #include “backgammon.h” • Change the prototype in header file, changes the prototypes in all the respective files
Header Files • By convention: Don’t put actual implementation code in “.h” files • “.h” files need to be included in .c files • #include copy/pastes binary into your current file • Header Files include: • Function prototypes • Constants / Global Variables
Compiling Multiple .c Files • Compile 3 files, generate 3 .o files, links them into 1 executable • Ex: gccboard.ccheck.cbackgammon.croll_die.c
Extern Variables / Methods • Added to header files as a forward declaration of variable • Simple allocates space for the variable, but you still need to declare and create the variable • Can be declared any number of times, but only defined once Ex: extern int x;
Testing Project 1 Manual vs Automation • Manual: Enter inputs into the file 2. Automation: Redirect file input and output
Redirect Input/Output • 1. Use “<” to redirect standard input from a file Ex: sheet < sheet-test1.in • 2. Use “>” to redirect standard output to a file Ex: sheet < sheet-test1.in > output