Results 1 to 16 of 16

Thread: clear the screen in ansi c

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    i'm writing an ansi c program. how do you clear the text from the screen? (i'm brand new to c and c++)

  2. #2
    Guest
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        printf("Text");
        system("cls");
        printf("More text");
        return 0;
    }

  3. #3
    Lively Member
    Join Date
    Sep 2000
    Location
    Singapore
    Posts
    78
    You can try this code and see:

    [quote]
    #include<stdio.h>

    int main() {

    int i;

    printf("Old Page");

    for(i = 0; i < 80; i++)
    printf("\n");

    printf("New Page!");

    return 0;
    }

  4. #4
    Guest
    that's just adding 80 new lines. It's easier to use the system() function.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yep -- and you can't guarantee the display size.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Hyperactive Member kourosh's Avatar
    Join Date
    Aug 1999
    Location
    Vancouver, British Columbia, Canada
    Posts
    256

    Question How do you do that?

    Hi, Sorry Parksie this is off topic but how do you get
    Mike "parksie" Parks to be color gradient?

    Thanks.
    ===========================
    Kourosh Gonabadi
    VB Programmer
    C++ Newbie
    Graphic Designer
    ===========================

  7. #7
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I take it screen clearing is platform dependant?
    Harry.

    "From one thing, know ten thousand things."

  9. #9
    Lively Member
    Join Date
    Sep 2000
    Location
    Singapore
    Posts
    78
    Yes that's why I use "\n"to create my own clear screen function. You will be able to use it regardless of platform.

  10. #10
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    True, but other platforms allow you to view different numbers of lines, so you can't be sure how many lines are visible.
    Harry.

    "From one thing, know ten thousand things."

  11. #11
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    well, there is always a limit to how many lines can fit on a screen, i doubt and would have more than 150. So if you were really parinoied you could do it for like 500 lines.

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  12. #12
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Hmmm well I don't know about 'always'... different platforms can allow for you to view a lot of lines. I'm sure you could add some platform-specific code to find out how many lines you needed, but then you might as well use the platform specific clear function.
    Harry.

    "From one thing, know ten thousand things."

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: How do you do that?

    Originally posted by kourosh
    Hi, Sorry Parksie this is off topic but how do you get
    Mike "parksie" Parks to be color gradient?
    Both me and Active simultaneously wrote gradient programs -- he went for two-point while I did rainbow, so different people used that. I couldn't be bothered to do any more on mine so he put rainbow into his
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    thanks for the help. I thought there would be a supplied CLS function or at least a \ command to do it.

  15. #15
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Are you programming for dos or just for a console?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    console. However, i'm doing it through vb. I thought there might be a string you could send to stdout to clear the screen, and since most console-mode apps are written in c/c++ i though i'd have better luck asking here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width