KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q41701: Using ANSI Escape Sequences in Microsoft C

Article: Q41701
Product(s): See article
Version(s): 5.00 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | S_QuickC | mspl13_c
Last Modified: 17-MAY-1989

Question:

How can I control the screen display using ANSI.SYS escape sequences
in my C program? For example, how can I clear the screen using the
escape sequences?

Response:

The easiest way to use ANSI escape sequences is to use them in the
printf statement, as follows:

#include <stdio.h>

/* ESC[2J escape sequence clears the screen;
   \033 represents the octal code for ESC */

#define  CLEAR "\033[2J"
main()
{
 printf ("%s screen is now cleared",CLEAR);
}

The best source of information on different escape sequences is "The
MS-DOS Encyclopedia," Pages 731-738.

Note: For escape sequences to work correctly, ANSI.SYS must be
installed.

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.