home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_01 / 1001046a < prev    next >
Text File  |  1991-10-06  |  1KB  |  64 lines

  1. /*
  2.  * Listing 2:  main() routine and test code for get_str().
  3.  * Includes the OS-dependent routines sys_getchar()
  4.  * and sys_putchar().
  5.  */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <bios.h>
  9. #include <string.h>
  10.  
  11. #define INBUFSIZ 70
  12. char inbuf[INBUFSIZ + 1];
  13.  
  14. void get_str( char *str, int len );
  15.  
  16. void main( void )
  17.     {
  18.  
  19.     while (1)
  20.         {
  21.         printf("\ntype 'quit' to quit.\nprompt> ");
  22.         get_str(inbuf, INBUFSIZ);
  23.  
  24.         if (stricmp(inbuf, "quit") == 0)
  25.             break;
  26.  
  27.         printf("  Got: \"%s\"\n", inbuf);
  28.         }
  29.     }
  30.  
  31.  
  32. /*********************************************************
  33.  * The following two routines will need to be changed,
  34.  * in order to use get_str() in a different environment.
  35.  *********************************************************/
  36.  
  37. /*
  38.  * Put a character to the output device.
  39.  * Expand \n to \r\n.
  40.  */
  41. void sys_putchar( char ch )
  42.     {
  43.  
  44.     putchar(ch);
  45.     if (ch == '\n')
  46.         putchar('\r');
  47.     }
  48.  
  49.  
  50. /*
  51.  * Get a character from the input device.
  52.  * Use the BIOS call so we can detect arrow keys.
  53.  */
  54. int sys_getchar( void )
  55.     {
  56.     int ch;
  57.  
  58.     ch = bioskey(0);    /* wait and get a key */
  59.  
  60.     if ((ch & 0xff) != 0)    /* if not an extended key, */
  61.         ch &= 0xff;            /* use only the ASCII part */
  62.     return (ch);
  63.     }
  64.