Microsoft KB Archive/68874

{|
 * width="100%"|

ANSI.SYS Escape Codes with printf for Screen Control

 * }

Q68874

-

The information in this article applies to:


 * The C Run-Time (CRT), included with:
 * Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
 * Microsoft C for OS/2, versions 5.1, 6.0, and 6.0a
 * Microsoft C/C++ for MS-DOS, version 7.0
 * Microsoft Visual C++, versions 1.0, 1.5

-

SUMMARY
The MS-DOS ANSI.SYS driver may be used to perform screen control functions in printf output. Setting screen attributes, positioning the cursor to a row and column, and clearing the screen are some examples of functions that may be done with this driver using the correct escape sequences.

MORE INFORMATION
The ANSI.SYS driver must be loaded from CONFIG.SYS in order for these functions to work correctly. All of the sequences start with the escape code &quot;\33&quot; (representing the value for escape in octal), followed by the appropriate set of characters needed to perform the desired function. The sample code below demonstrates some of these functions.

This topic is discussed in detail on pages 224-225 of the Microsoft Press book &quot;Variations in C.&quot; Another good source of information on ANSI.SYS and the ANSI escape sequences is &quot;The MS-DOS Encyclopedia&quot; (on pages 731-738) or in most MS-DOS manuals under the PROMPT command.

In OS/2, the ANSI driver is enabled by default for all sessions except the Presentation Manager. To enable ANSI support in the DOS box, a line must be added to the CONFIG.SYS file. See your OS/2 documentation for more information on the exact syntax.

Sample Code
/* Compile options needed: none


 * 1) include 

void main( void) {  int row = 10; int col = 20; int num = 1;

printf( &quot;\33[2J&quot;);               // clears the screen printf( &quot;\33[%d;%dH&quot;, row, col); // positions the cursor at                                     // row 10, column 20 printf( &quot;\33[%dA&quot;, num);         // moves the cursor up one line printf( &quot;\33[%dB&quot;, num);         // moves the cursor down one line printf( &quot;\33[7m&quot;);               // sets the attribute to reverse // video } Additional query words: kbinf 5.10 6.00 6.00a 6.00ax 7.00 1.00 1.50

Keywords : kb16bitonly

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCRT