clrscr() function

This is a discussion on clrscr() function within the C Programming forums, part of the General Programming Boards category; does a similar function clrscr() from conio.h exists in gcc ?...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    clrscr() function

    does a similar function clrscr() from conio.h exists in gcc ?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Well, you can use system("cls") . . . check the FAQ.

    [edit]
    Found it: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    Assuming you're using Linux you should have a look at ncurses. I'm sure you will not have problems finding a nice tutorial.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    yes, i know that... but i'm looking for smthing portable from linux to win. another way not using any external commands ?

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Every option that I know of listed in the FAQ - there is no universal solution in the standard.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    167
    thank you!

    really helps!

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    53
    I believe I have tried to use different ways to clear the screen, but almost everyone of them takes a lot of time and (I think) memory.
    I think I tried adding a lot of spaces using "for"
    I hope that will save you some time!
    Alastor
    "I tend to use my inbox as a todo list. But that's like using a screwdriver to open bottles; what one really wants is a bottle opener" - Paul Graham

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I think I tried adding a lot of spaces using "for"
    This works, but it doesn't position the cursor at (0,0). If you can live with that, fine, otherwise you need to call a function to set the cursor (the FAQ has a Windows version).

    For portability, you could use the preprocessor:
    Code:
    void clear_screen(void) {
    #ifdef unix  /* not standard, but usually defined */
        clrscr();
    #else
        system("cls");
    #endif
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    Quote Originally Posted by dwks
    This works, but it doesn't position the cursor at (0,0). If you can live with that, fine, otherwise you need to call a function to set the cursor (the FAQ has a Windows version).

    For portability, you could use the preprocessor:
    Code:
    void clear_screen(void) {
    #ifdef unix  /* not standard, but usually defined */
        clrscr();
    #else
        system("cls");
    #endif
    }
    I'm almost completely sure that clrscr is a Borland invention for MS-DOS/Windows based systems and isn't available on a Unix system. If you're lucky, putchar('\f') might work, but otherwise you'll be doing something system-dependent or relying on a loop or a system call.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Okay, then, on UNIX use system("clear");.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Or just realise that the vast majority of command line tools do not begin with any attempt to clear the screen. If they did, they would soon become majorly annoying just to look at and probably majorly annoying if you attempted to say pipe the output to another program.

    The typical evolution of a programmer
    Day 1 - discover '\a' and abuse it
    Day 2 - discover clearing the screen and abuse it
    Day 3 onwards - concentrate on providing useful tools rather than trying to impose your ego on the users.

  12. #12
    Rabble Rouser Slacker's Avatar
    Join Date
    Dec 2005
    Posts
    116
    >Day 1 - discover '\a' and abuse it


    >Day 2 - discover clearing the screen and abuse it
    Presumably because they got tired of abusing '\a'.

    >Day 3 onwards - concentrate on providing useful tools rather than trying to impose your ego on the users.
    Only two days of abuse? You've been extremely lucky in the programmers that you've known.
    Code:
    void
      main()
         {
    #define woobly "stdio.h"
    #include woobly
           while (1  )
         printf ("\a" );
    return 'q';}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  4. Replies: 4
    Last Post: 11-23-2003, 06:15 AM
  5. Replies: 5
    Last Post: 02-08-2003, 06:42 PM

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