Clear Console Screen

This is a discussion on Clear Console Screen within the C Programming forums, part of the General Programming Boards category; Hello guys, I'm fully aware I can clear the command line interface with: Code: system("cls"); however doesn't this limit my ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    36

    Clear Console Screen

    Hello guys,

    I'm fully aware I can clear the command line interface with:

    Code:
    system("cls");
    however doesn't this limit my program to Windows only?, if so are they any good techniques to maintain portability.
    Last edited by Cero.Uno; 04-21-2008 at 04:10 PM.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Code:
    for (i = 0 ; i < some_number_that_you_guess_is_the_number_of_console_lines ; i++) printf("\n") ;
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    I don't think there is a portable solution, but most terminal emulators support escape sequences:

    e.g. printf("\033[2J\n"); /* vt100, clear screen escape sequence */

    Additional code is needed to move the cursor.
    This work on unix-like systems, don't know with windows.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Or look in the Frequently Asked Questions: http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clear Screen Again!!!
    By trang in forum C Programming
    Replies: 3
    Last Post: 12-13-2003, 08:36 AM
  2. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM
  3. How to clear the screen?
    By Zopyrus in forum C++ Programming
    Replies: 8
    Last Post: 11-07-2003, 10:20 PM
  4. Clear Screen
    By KneeGrow in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2003, 11:17 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21