Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9296891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:56:05+00:00 2026-06-18T21:56:05+00:00

I wrote a small console program that requires an occasional clearing of the terminal

  • 0

I wrote a small console program that requires an occasional clearing of the terminal screen. I wrote the code on/for a *nix system and used system("clear") in these instances. Once my code was complete I reviewed it to assess the portability of my code. The above method of clearing the screen was my only apparent portability issue. I then looked for other possible ways for clearing the terminal and found some documentation on ANSI Cursor Indexing, specifically:

void cls() {
  //27 is ESC ASCII char
  printf("%c[2J",27);   //clears screen
  printf("%c[0;0H",27); //sets cursor at [0,0]
}

To my surprise this code worked wonderfully on my *nix system. I was wondering, is this ANSI Cursor Indexing Scheme portable? Will this code compile and behave expectedly on all systems with a C standard compiler?”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:56:07+00:00Added an answer on June 18, 2026 at 9:56 pm

    ANSI and VT100 escape sequences are very close, which means that if the terminal is either of those two, the set of commands listed above are definitely going to work. Bear in mind however that ANSI is a superset of VT100, so VT100 compatible terminals will NOT understand ALL ANSI sequences.

    VT100 terminal emulators are among the absolutely most common ones (including the default for xterm and other “X-windows style shells”.

    Clearly, say, a Volker-Craig 404 terminal emulator [does anyone use those? ;)] will NOT understand either ANSI or VT100 escape sequences, or indeed ANY escape sequences.

    I would point out also that your code will be simpler by incorporating your ESC into the constant string:

    printf("\033[2J");
    

    or if you want to make it a little more readable:

    #define ESC_STR "\033"
    
    printf(ESC_STR"[2J");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small program, that creates files at an interval of 1 minute.
I wrote a small piece of code that rapidly read and write to a
I wrote a small Shotgun app, however, the section of code that needs to
I imported LuaInterface into a console project, referenced it, and wrote a small test
I need to write a small console app (patch) that turns off the print
I wrote a small test program for flipperview. I have 3 views. I call
I wrote a small app that turns out to be using a lot of
I need to write tests(using google testing framework) for small study program that was
I'm developing a small haskell program that uses an external static library I've developed
I have a small console application, that asks for a values to count with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.