k.txt
Upload User: harvey99
Upload Date: 2020-01-11
Package Size: 938k
Code Size: 2k
Category:

Other Books

Development Platform:

CHM

  1.  返回>>C语言函数大全
  2. 函数名: kbhit
  3. 功  能: 检查当前按下的键
  4. 用  法: int kbhit(void);
  5. 程序例: 
  6. #include <conio.h> 
  7. int main(void)
  8. {
  9.    cprintf("Press any key to continue:");
  10.    while (!kbhit()) /* do nothing */ ;
  11.    cprintf("rnA key was pressed...rn");
  12.    return 0;
  13. }
  14.  
  15.  
  16.  
  17. 函数名: keep
  18. 功  能: 退出并继续驻留
  19. 用  法: void keep(int status, int size);
  20. 程序例:
  21. /***NOTE:
  22.    This is an interrupt service routine.  You
  23.    can NOT compile this program with Test
  24.    Stack Overflow turned on and get an
  25.    executable file which will operate
  26.    correctly.  Due to the nature of this
  27.    function the formula used to compute
  28.    the number of paragraphs may not
  29.    necessarily work in all cases.  Use with
  30.    care!  Terminate Stay Resident (TSR)
  31.    programs are complex and no other support
  32.    for them is provided.  Refer to the
  33.    MS-DOS technical documentation
  34.    for more information.  */
  35. #include <dos.h>
  36. /* The clock tick interrupt */
  37. #define INTR 0x1C
  38. /* Screen attribute (blue on grey) */
  39. #define ATTR 0x7900
  40. /* reduce heaplength and stacklength
  41. to make a smaller program in memory */
  42. extern unsigned _heaplen = 1024;
  43. extern unsigned _stklen  = 512;
  44. void interrupt ( *oldhandler)(void);
  45. void interrupt handler(void)
  46. {
  47.    unsigned int (far *screen)[80];
  48.    static int count;
  49. /* For a color screen the video memory
  50.    is at B800:0000.  For a monochrome
  51.    system use B000:000 */
  52.    screen = MK_FP(0xB800,0);
  53. /* increase the counter and keep it
  54.    within 0 to 9 */
  55.    count++;
  56.    count %= 10;
  57. /* put the number on the screen */
  58.    screen[0][79] = count + '0' + ATTR;
  59. /* call the old interrupt handler */
  60.    oldhandler();
  61. }
  62. int main(void)
  63. {
  64. /* get the address of the current clock
  65.    tick interrupt */
  66. oldhandler = getvect(INTR);
  67. /* install the new interrupt handler */
  68. setvect(INTR, handler);
  69. /* _psp is the starting address of the
  70.    program in memory.  The top of the stack
  71.    is the end of the program.  Using _SS and
  72.    _SP together we can get the end of the
  73.    stack.  You may want to allow a bit of
  74.    saftey space to insure that enough room
  75.    is being allocated ie:
  76.    (_SS + ((_SP + safety space)/16) - _psp)
  77. */
  78. keep(0, (_SS + (_SP/16) - _psp));
  79. return 0;
  80. }
  81.