首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于tc.中断有关问题的处理

2012-09-02 
关于tc.中断问题的处理.因为tc是单线程的.1.当程序遇到问题的时候,死循环.或者 我想退出程序的时候 想通过

关于tc.中断问题的处理.
因为tc是单线程的. 

1.当程序遇到问题的时候,死循环. 或者 我想退出程序的时候 想通过按键来实现. 比如我在做一个小游戏. 在游戏过程中 我想通过 【ESC】键就退出游戏。

2我想在游戏界面旁边做一个 电子时钟. 因为时钟每一秒需要刷新一次.但是同时游戏又在进行.我想通过中断来实现. 各位大虾给点思路.. 或者提供点资源. 不胜感激.


[解决办法]
上帖错了,应该是setvect按Ctrl+F1
下面是BC++3.1里面的例子

C/C++ code
/***NOTE:    This is an interrupt service routine.  You can NOT compile this    program with Test Stack Overflow turned on and get an executable    file which will operate correctly. */#include <stdio.h>#include <dos.h>#include <conio.h>#define INTR 0X1C    /* The clock tick interrupt */#ifdef __cplusplus    #define __CPPARGS ...#else    #define __CPPARGS#endifvoid interrupt ( *oldhandler)(__CPPARGS);int count=0;void interrupt handler(__CPPARGS){/* increase the global counter */   count++;/* call the old routine */   oldhandler();}int main(void){/* save the old interrupt vector */   oldhandler = getvect(INTR);/* install the new interrupt handler */   setvect(INTR, handler);/* loop until the counter exceeds 20 */   while (count < 20)      printf("count is %d\n",count);/* reset the old interrupt handler */   setvect(INTR, oldhandler);   return 0;} 

热点排行