Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5283
Number of posts: 16725

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Clear screen Posted by stevenewilson on 5 Sept 2002 at 8:23 AM
For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)

And while I'm at it, since I'm new to message boards, I was just wondering: Whenever somebody posts an answer to one of my questions and solves my problem, my natural impulse is to e-mail that person to say thanks. However, I thought I had better check on the obvious etiquette issue: Is e-mailing one's thanks considered unnecessary, or perhaps even a minor annoyance (i.e., yet another e-mail to read)? Or on the contrary, is this appreciated? Alternatively, perhaps I should just say "thanks in advance" when posting my question? What is the established practice in this regard?
Report
Re: Clear screen Posted by Darius on 5 Sept 2002 at 11:54 AM
: For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)

No, there is no standard function to clear the screen. The standard doesn't think of screens and keyboards, everything is just a stream. If you are going to do complex console manipulation (and that may include even simple things like clearing the screen) then you should use a cross-platform library such as ncurses or SLang. For clearing the screen though, you can just spew a bunch of newlines out and that should get the necessary effect.

:
: And while I'm at it, since I'm new to message boards, I was just wondering: Whenever somebody posts an answer to one of my questions and solves my problem, my natural impulse is to e-mail that person to say thanks. However, I thought I had better check on the obvious etiquette issue: Is e-mailing one's thanks considered unnecessary, or perhaps even a minor annoyance (i.e., yet another e-mail to read)? Or on the contrary, is this appreciated? Alternatively, perhaps I should just say "thanks in advance" when posting my question? What is the established practice in this regard?
:

These are just my personal views.

Don't email me. If you really want to email me, then use the Programmer's Heaven mail system (i.e. "Write Message"). Of course, don't bother just to say thanks. No one will complain if you say, "Thanks, that solved my problem" as a reply (obviously don't post a new thread for that). I personally, don't like "Thanks in advance". Actually, that's not accurate, I don't care (actually I don't care about thanks at all). However, I find it ridiculous for anyone to say thanks in advance, when they quite possibly might get no help at all. Also, though I don't care about thanks, I do kind of like knowing that the problem is over and done with. So posting a reply once the problem is solved is nice. As far as I'm concerned, just "It worked", or better "It worked, but I had to do X and Y as well to get it to work", or "I decided to try something else", or anything that might be helpful is enough.

While typically this is given to people who have violated every reasonable posting practice, you may also find some things that will give you an idea of what you should do, what things to avoid, and how to maximize the quality and speed of the replies you get,
http://www.tuxedo.org/~esr/faqs/smart-questions.html


"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion

Report
Re: Clear screen Posted by funkydude9 on 5 Sept 2002 at 11:56 AM
You mean like:

system("CLS");

..or:

#include <conio.h>
clrscr();
Report
Re: Clear screen Posted by Darius on 5 Sept 2002 at 11:56 AM
: You mean like:
:
: system("CLS");
:
: ..or:
:
: #include <conio.h>
: clrscr();
:

Neither of which are standard.

"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion

Report
Re: Clear screen Posted by stevenewilson on 6 Sept 2002 at 6:17 AM
: : You mean like:
: :
: : system("CLS");
: :
: : ..or:
: :
: : #include <conio.h>
: : clrscr();
: :
:
: Neither of which are standard.
:
: "We can't do nothing and think someone else will make it right."
: -Kyoto Now, Bad Religion
:
:

Thanks for the tip. clrscr(); doesn't work for me, despite my including <conio.h> ("warning: 'clrscr' undefined...). However, system("CLS"); works fine.

Report
Re: Clear screen Posted by stevenewilson on 6 Sept 2002 at 6:14 AM
: You mean like:
:
: system("CLS");
:
: ..or:
:
: #include <conio.h>
: clrscr();
:

Thanks for the tip. clrscr(); doesn't work for me, despite my including <conio.h> ("warning: 'clrscr' undefined...). However, system("CLS"); works fine.

Report
Re: Clear screen Posted by Darius on 6 Sept 2002 at 6:42 AM
: : You mean like:
: :
: : system("CLS");
: :
: : ..or:
: :
: : #include <conio.h>
: : clrscr();
: :
:
Thanks for the tip. clrscr(); doesn't work for me, despite my including <conio.h> ("warning: 'clrscr' undefined...). However, system("CLS"); works fine.
...
Until you recompile for Linux (let's say) and get

bash: cls: command not found

as output anytime you try to clear the screen.

"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion

Report
Re: Clear screen Posted by kenson_lat on 6 Sept 2002 at 4:22 AM
: For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)

I used to submit to BeOS mailling lists in the past, and someone from BeCodeTalk gave an interesting way to clear the screen:

printf("\033[H\033[J");

Not very sure why it works though, or even what it means.....
Of course, this method would probably be far from "standard".
Report
Re: Clear screen Posted by Darius on 6 Sept 2002 at 6:06 AM
: : For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)
:
: I used to submit to BeOS mailling lists in the past, and someone from BeCodeTalk gave an interesting way to clear the screen:
:
: printf("\033[H\033[J");
:
: Not very sure why it works though, or even what it means.....
: Of course, this method would probably be far from "standard".
:
What that does is send terminal codes to the screen \033 is ESC. It won't work in general, it will only work for terminals where that escape sequence means clear the screen. However, for, for example, the Windows command prompt, that wouldn't work.

"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion

Report
Re: Clear screen Posted by stevenewilson on 6 Sept 2002 at 6:32 AM
: : For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)
:
: I used to submit to BeOS mailling lists in the past, and someone from BeCodeTalk gave an interesting way to clear the screen:
:
: printf("\033[H\033[J");
:
: Not very sure why it works though, or even what it means.....
: Of course, this method would probably be far from "standard".
:

Thanks for the suggestion. Actually, I'm afraid I wasn't able to get it to work. However, somebody else suggested the following, and it works fine:

#include <process.h> or <stdlib.h>

system("CLS");

Report
Re: Clear screen Posted by denniscpp on 8 Sept 2002 at 9:52 AM
if your output window's 25 rows, use this:

{
   for (register int i = 0; i < 25; i++)
      puts("");
}

Report
Re: Clear screen Posted by stevenewilson on 9 Sept 2002 at 4:28 AM
: if your output window's 25 rows, use this:
:
:
{
:    for (register int i = 0; i < 25; i++)
:       puts("");
: }

:

Thanks! Somebody else suggested the following:

system("CLS");

...and it works well, too.


Report
Re: Clear screen Posted by denniscpp on 9 Sept 2002 at 10:16 PM
after my statements're executed, the insertion point'll not located at the beginning of the screen.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.