Turbo C获取环境变量与寄存器信息实践

需积分: 30 39 下载量 60 浏览量 更新于2024-08-05 收藏 13.06MB PDF 举报
"获取寄存器信息_技术要点-client-side.data.storage.keeping.it.local.14919" 本文主要介绍了如何在C语言中获取和处理系统环境变量以及寄存器信息,这些都是C语言编程中非常基础但重要的技术点。 首先,获取环境变量的技术要点在于使用内置全局变量`environ`。`environ`是一个字符型数组,存储了系统中的所有环境变量。通过循环遍历`environ`数组,可以输出系统中当前设置的所有环境变量。以下是一个简单的示例程序,演示如何打印所有环境变量: ```c #include <stdio.h> #include <dos.h> int main(void) { char *path, *ptr; int i = 0; //clrscr(); puts("This program is to get the information of environ."); while (environ[i]) { printf(">>%s\n", environ[i++]); } printf("Press any key to quit..."); getch(); return 0; } ``` 此外,文章还提到了一个扩展应用,即读者可以根据这个例子学习如何将环境变量保存到文本文件中,或者定时保存环境变量。 接下来,文章转向了获取寄存器信息的技术要点。在DOS环境下,可以通过调用`segread()`函数来获取寄存器的当前值。`segread()`函数位于`dos.h`头文件中,它的功能是将段寄存器的值放入传入的`SREGS`结构体中。`SREGS`结构体包含了处理器的段寄存器信息,这对于理解低级别内存管理和程序执行的底层细节至关重要。 在C语言编程中,熟悉并能够正确使用这些基本概念和技术对于编写高效、稳定的程序至关重要。例如,了解环境变量的使用可以帮助开发者更好地控制程序的行为,适应不同的运行环境。而掌握寄存器读取则对于进行系统级编程或优化性能时非常有用。 此外,提供的资源摘要中还列举了一系列的实例,覆盖了从基础的进制转换、条件判断,到复杂的数组操作、字符串处理、函数应用、指针使用等多个方面,这些都是C语言学习过程中的核心知识点。通过这些实例,读者可以深入理解C语言的特性和用法,提升编程能力。 例如,实例001至004介绍了不同进制之间的转换,实例005至008展示了条件判断的应用,而实例009至014则涵盖了循环结构的各种实际应用。在数组操作部分,实例022至028涉及了数组的逆序、统计、排序等功能。字符串处理的实例029至035包括了字符串的翻转、替换、排序等。函数的使用在实例036至038中得到了体现,其中包含递归和参数传递。最后,宏定义和位运算的实例049和050展示了预处理指令和位操作在C语言中的应用。 指针部分,从实例051到064,讲解了指针作为变量、与数组的结合以及在函数中的应用,这些都是C语言中高级和关键的概念,对于理解和操作内存至关重要。 这些知识点和实例提供了全面的C语言学习素材,涵盖了从基础知识到高级应用的多个层次,适合初学者和有一定经验的开发者进行学习和实践。

Before Playstation, there was Pong, at one time the ultimate in video game entertainment. For those of you not familiar with this game please refer to the Wikipedia entry (http://en.wikipedia.org/wiki/Pong) and the many fine websites extolling the game and its virtues. Pong is not so very different in structure from the Billiard ball simulation that you developed earlier in the course. They both involve a ball moving and colliding with obstacles. The difference in this case is that two of the obstacles are under user control. The goal of this project is to develop your own version of Pong in MATLAB using the keyboard as input, for example, one player could move the left paddle up and down using the q and a keys while the right paddle is controlled with the p and l keys. You may check the code for the Lunarlander game which demonstrates some of the techniques you can use to capture user input. You will also probably find the plot, set, line and text commands useful in your program. You have used most of these before in the billiard simulation and you can use Matlabs online help to get more details on the many options these functions offer. Your program should allow you to play a game to 11 keeping track of score appropriately. The general structure of the code is outlined below in pseudo code While not done Update Ball State (position and velocity) taking into account collisions with walls and paddles Check for scoring and handle appropriately Update Display Note that in this case it is implicitly assumed that capturing the user input and moving the paddles is being handled with callback functions which removes that functionality from the main loop. For extra credit you could consider adding extra features like spin or gravity to the ball flight or providing a single player mode where the computer controls one of the paddles.

2023-05-30 上传