The .h File
The header file is used to declare function prototypes
In this case: the main.c file includes the myfunction.h header file to get access to the myfunction.c functions.
As this Prototypes. these are then defined in the myfunction.c source file.
The myfunction.c file defines the functions:
main.c file include myfunction.h header file ——> the function of myfunction.h header file is defined in myfunction.c source
The Static Library
To share functionality across programs, it is possible to create a library file( .lib file, contains compiled function code)
Application Programming Interface (API)(应用程序编程接口)
And we need load p1colour.h and p1colour.lib into visual studio:
First parament is the colour of text and the second one is background colour.
Locate the p1colour.h file on disk, and add it to the project:
And then Add the library file to the Visual Studio Project:
Go to the Linker settings(Find the “Additional Dependencies” field of the Input section):
Add the .lib to the Linker input:
Add p1colour.lib here and then confirm:
Type the name of the file
Alternative Keyboard Input
getch()
when the user type in the input will not be showed on the screen, but Keyboard input is passed directly to the program
it is non-standard, and this implementation is Windows platform only.
kbhit()
be used to detect whether a key has been pressed
Detecting the Arrow Keys:
When an Arrow Key is pressed, _getch must be called twice to retrieve which Arrow Key was pressed
exercise:
Requirement(12x01a)
Implementation
Test
Errors Encountered
Compiler cannot open the p1colour file.
Debug & Lessons Learnt
Should remember to put those files into the same directory of the project.
Can also take reference from the folder: