ID Number: Q68874
3.x 4.x 5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a
MS-DOS | OS/2
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 "\33" (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 "Variations in C." Another good source of information on
ANSI.SYS and the ANSI escape sequences is "The MS-DOS Encyclopedia"
(on pages 731-738) or in most MS-DOS manuals under the PROMPT command.
Under 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
*/
#include <stdio.h>
void main( void)
{
int row = 10;
int col = 20;
int num = 1;
printf( "\33[2J"); // clears the screen
printf( "\33[%d;%dH", row, col); // positions the cursor at row 10,
// column 20
printf( "\33[%dA", num); // moves the cursor up one line
printf( "\33[%dB", num); // moves the cursor down one line
printf( "\33[7m"); // sets the attribute to reverse
// video
}
Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00