#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    0
    Rep Power
    0

    Clearing the screen on a linux system


    I am writng a c++ program. In the program I want to clear the screen. How do I do that?


    Thanks,
    Jonathan Donaghe
    http://www.functional-image.com
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    What compiler are you using?
    I am guessing this is a console application and not a windows application or you wouldn't be asking that question.
    If you are using a Borland compiler you can include the conio.h header and use the function clrscr(). I am not sure which boreland compilers that support this function anymore. I know microsoft does not support this. I am not sure, but I don't believe *nix compilers do either.
  4. #3
  5. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    I'm sorry, I just realized you had Linux in your subject line.
    In the case of clearing the screen in a linux app, I don't know of a standard function that does this. If someone else does, I would love to know also. The only method I know of is to print around 21 blank lines to the screen to accomplish this task.
    I know there must be different ways to accomplish this though, especially if you are using ncurses.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    0
    Rep Power
    0

    I have found the answer


    Thanks for your help. But I have found the way to clear the screen. You can use a function called system() in the <stdlib.h> library. If you are trying to clear the screen in dos you would use:
    system("cls")

    If you are trying to clear the screen in Linux/Unix you would use:
    system("clear")

    This function will also call the rest of the system calls.


    Thanks,
    Jonathan Donaghe
  8. #5
  9. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    I know of that, remember trying it once. I believe I ran into some sort of problem with it, just don't remember what.
    Glad you found it.
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    Onslaught, I think the problem you might be referring to is the return value of the system() call (at least in DOS/Windows versions). The problem is that the system() call will always return 0, even if the program that was executed returns a different value. The *nix version of system() is much better because it returns the value from the program that was executed.
  12. #7
  13. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Actually, if I remember correctly, I can't say for sure, it has been years since I have actually tried to do it, but I believe that it was actually executing the command before I needed it to.

IMN logo majestic logo threadwatch logo seochat tools logo