Header Files, Static Libraries, P1Colour, Input Polling

本文详细介绍了如何在C语言项目中使用库文件和API,包括如何包含头文件、定义函数原型、创建静态库以及在Visual Studio中加载库文件。文章还探讨了键盘输入函数getch()和kbhit()的使用,以及解决编译错误的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值