home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / PCLRSCRN.HOW < prev    next >
Text File  |  1997-07-05  |  4KB  |  126 lines

  1. +++Date last modified: 05-Jul-1997
  2.  
  3.       C Language Topic:  Clearing a Text Mode DOS PC screen
  4. ====================================================================
  5.  
  6.   Compiled by Mike Demski - 75324.3574@compuserve.com
  7.  
  8.  The following question is often asked in the FidoNet C_ECHO and
  9.  other C/C++ programming forums/areas:
  10.  
  11.  "How do I clear a "text mode DOS PC" screen using the C Language?"
  12.  
  13.  Answers to the above question vary.  First, if portability is of
  14.  concern, a portable clear screen function "clrscr()" exists within
  15.  the SNIPPETS archive.  Within SNIPPETS, please refer to:
  16.  
  17.  "Vidport.C - DOS: Portable gotoxy(), clrscr(), etc. equivalents"
  18.  
  19.  Also, many compiler vendors supply a clear screen function,
  20.  which is "compiler specific" (i.e. - non portable).  (See below.)
  21.  
  22. ====================================================================
  23.    Compiler (Vendor)     *  Clear Screen Function  *   Header File
  24. ====================================================================
  25.  Borland Turbo C++ 3.0,  *        clrscr()         *    conio.h
  26.  Borland C++ 3.x, 4.xx   *                         *
  27. --------------------------------------------------------------------
  28.  M.S. Quick C 2.5,       *                         *
  29.  M.S. Visual C++ 1.52,   *     _clearscreen()      *    graph.h
  30.  Watcom C/C++ 10.x       *                         *
  31. --------------------------------------------------------------------
  32.  Mix Power C 2.2.0       *        clrscrn()        *    bios.h
  33. --------------------------------------------------------------------
  34.  Symantec C++ v7.x,      *  [ See example below ]  *    disp.h
  35.  Zortech C 2.18          *    disp_xxxx() family   *
  36. --------------------------------------------------------------------
  37.  
  38. Examples of specific vendor approaches to clearing a PC screen in DOS:
  39.  
  40. --------------------------------------------------------
  41. /* Example - Borland Turbo C++ 3.0, Borland C++ 3.1, and
  42.              Borland C++ 4.x Clear Screen (DOS PC)   */
  43.  
  44. #include <conio.h>
  45.  
  46. int main(void)
  47. {
  48.   clrscr();
  49.  
  50.   return 0;
  51. }
  52. --------------------------------------------------------
  53. --------------------------------------------------------
  54. /* Example - M.S. Quick C 2.5, M.S. VC++ 1.52, and
  55.              Watcom 10.x Clear Screen (DOS PC)   */
  56.  
  57. #include <graph.h>
  58.  
  59. int main(void)
  60. {
  61.   _clearscreen(_GCLEARSCREEN);  /* or _clearscreen(0) */
  62.  
  63.   return 0;
  64. }
  65. --------------------------------------------------------
  66. --------------------------------------------------------
  67. /* Example - Power C 2.2.0 Clear Screen (DOS PC)  */
  68.  
  69. #include <bios.h>
  70.  
  71. int main(void)
  72. {
  73.   clrscrn();
  74.  
  75.   return 0;
  76. }
  77. --------------------------------------------------------
  78.  
  79. To clear the PC screen in DOS with Symantec C++ or
  80. Zortech C++, use the disp_xxxx() functions to set the
  81. cursor to the beginning of the screen and then call the
  82. disp_eeop() function to erase to the end of the screen.
  83. --------------------------------------------------------
  84. /* Example - Symantec C++ and Zortech C++ (all versions)
  85.              Clear Screen (DOS PC)   */
  86.  
  87. #include <disp.h>
  88.  
  89. int main(void)
  90. {
  91.    disp_open();
  92.    disp_move(0, 0);
  93.    disp_eeop();
  94.    disp_close();
  95.  
  96.    return 0;
  97. }
  98. --------------------------------------------------------
  99. ========================================================
  100.  
  101. Furthermore, when using ANSI.SYS (or an equivalent), one
  102. may clear the screen using ANSI screen control codes.
  103. Within the SNIPPETS archive, please refer to ANSICODE.H,
  104. which defines: ANSI_cls(), or note the following equivalent
  105. ANSI screen control code clear screen example:
  106.  
  107. --------------------------------------------------------
  108. /* Example - Using ANSI screen control codes to
  109.              Clear Screen (DOS PC)
  110.  
  111.      Note:   ANSI.SYS or equivalent must be loaded
  112.              for this example to clear the PC screen.  */
  113.  
  114. #include <stdio.h>
  115.  
  116. #define  ESC  27
  117.  
  118. int main(void)
  119. {
  120.  
  121.   printf("%c[2J", ESC);
  122.  
  123.   return 0;
  124. }
  125. --------------------------------------------------------
  126.