ANSI clear screen [MS & Borland]

R

ritchie

Hi,

I am trying to clear the screen in my program.
I am loking for something that will work on all compilers, especially
Borland & MS Visual Studio 6.
On Visual studio I used 'system("cls");' and this works fine but this
won't work for Borland.
On Borland I used 'clrscr() ' function and it worked ok, but not for
Visual Studio.

Is there anything that will clear the screen in both and maybe also
work on gcc?
In Borland I want to use 'easywin.exe' instead of the console window
and clear the screen.

I thought that 'system("cls");' would work with this?

Any ideas?

Thanks in advance,
Ritchie
 
L

lallous

Search for "Microsoft Knowledge Base Article - 99261"

That should work on both compilers given that you're making a win32 console
application.
 
C

CBFalconer

ritchie said:
I am trying to clear the screen in my program.
I am loking for something that will work on all compilers,
especially Borland & MS Visual Studio 6.

Since you carefully read the FAQ, you are now aware that this
cannot be done in standard C. About the closest you can come is:

puts("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

and you may need to adjust the \n count.

After all that, don't do it. There is nothing more annoying than
gratuitious screen clearings from imbecelic programs removing data
I want to remain visible.
 
T

Tristan Miller

Greetings.

ritchie said:
Is there anything that will clear the screen in both and maybe also
work on gcc?

Maybe putchar('\f')... if that doesn't work, use the compiler-provided
implementations and wrap them around #defines. (Presumably each
compiler will #define some macro identifying it. I know GCC does. If
Borland and Microsoft don't, you're probably out of luck.)
 
R

Richard Heathfield

CBFalconer said:
Since you carefully read the FAQ, you are now aware that this
cannot be done in standard C. About the closest you can come is:

puts("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

and you may need to adjust the \n count.

And that (as you know) isn't a portable technique either.
After all that, don't do it. There is nothing more annoying than
gratuitious screen clearings from imbecelic programs removing data
I want to remain visible.

Nothing wrong with clearing the screen (by which I really mean the current
terminal window), as long as he puts the old data back afterwards. :)
 
I

Irrwahn Grausewitz

Richard Heathfield said:
CBFalconer wrote:

[How to clear screen]
Nothing wrong with clearing the screen (by which I really mean the current
terminal window), as long as he puts the old data back afterwards. :)

No need to put it back. I use a damp cloth and a tiny little bit of
detergent to clear the screen, and the data doesn't get rubbed off -
it stays nice and clear where it was. :)
 
M

Mark McIntyre

Richard Heathfield said:
CBFalconer wrote:

[How to clear screen]
Nothing wrong with clearing the screen (by which I really mean the current
terminal window), as long as he puts the old data back afterwards. :)

No need to put it back. I use a damp cloth and a tiny little bit of
detergent to clear the screen, and the data doesn't get rubbed off -
it stays nice and clear where it was. :)

I tried this on my teletype and now my doctor says I'll have to write
wrong-handed till the burns heal. :-(
 
M

Morris Dovey

Mark said:
I tried this on my teletype and now my doctor says I'll have to write
wrong-handed till the burns heal. :-(

Worse - I tried it on my CNC router and now I have mortise and
tenon joints...
 
M

Mark McIntyre

Worse - I tried it on my CNC router and now I have mortise and
tenon joints...

See, these problems wouldn't arise if people didn't give offtopic
answers here. Any fule kno that your kind of router is pronounced to
rhyme with shouter, and the sort you /should/ have wiped with solvent
is pronounced to assonate with tooter. If only you yanks could learn
to spel too, we'd be laffin.
 
C

CBFalconer

Richard said:
And that (as you know) isn't a portable technique either.

Note underlined word above :)
Nothing wrong with clearing the screen (by which I really mean the
current terminal window), as long as he puts the old data back
afterwards. :)

Disagree. Consider a calculator program. While using it I want
the data that was previously left on my screen.
 
G

Gordon Burditt

I am trying to clear the screen in my program.
1. What screen? Who says there is one?
2. Which screen? Who says there is only one?

ANSI C does not require a screen. Having stdin and stdout connected
to an ASR-33 teletype meets the requirements (what few there are
in this respect) of ANSI C. There is *NO* ANSI C solution to your
problem.
I am loking for something that will work on all compilers, especially
Borland & MS Visual Studio 6.

How does one even try clear the screen on a terminal that prints
on paper? Is this the screen that prevents dirt from clogging up
the bathtub drain?

Gordon L. Burditt
 
A

Andrew Robert

Try using the following:

#define CLRSCRN fprintf ( stdout,"\033[J" )

When you want to clear the screen, all you need to do is

CLRSCRN;
 
K

Kevin Goodsell

Andrew said:
Try using the following:

#define CLRSCRN fprintf ( stdout,"\033[J" )

When you want to clear the screen, all you need to do is

CLRSCRN;

Please don't top-post, and please don't post non-portable answers. This
groups is for the C language, not for tricks that won't even work on
most platforms. This is in the FAQ:

http://www.eskimo.com/~scs/C-faq/q19.4.html

-Kevin
 
R

Richard Heathfield

CBFalconer said:
Note underlined word above :)


Disagree. Consider a calculator program. While using it I want
the data that was previously left on my screen.

Clearly, you would not use a calculator that clears your screen, then.
(Neither do I. I keep forgetting that bc doesn't clear the screen, and I'm
always relieved to see that it doesn't, for precisely the reason you gave.)

On the other hand, does your usual source code text editor take full control
over the window in which its output appears? Mine does. And yet I use it
cheerfully.

In other words, it all depends.
 
R

Richard Heathfield

Andrew said:
Try using the following:

#define CLRSCRN fprintf ( stdout,"\033[J" )

When you want to clear the screen, all you need to do is

CLRSCRN;

I tried this on one of my machines at home, and it just printed a little
backward-arrow thing, followed by [J

It certainly didn't clear the screen.
 
S

Simon Biber

Richard Heathfield said:
On the other hand, does your usual source code text editor take full
control over the window in which its output appears? Mine does. And
yet I use it cheerfully.

When I invoke my usual source code text editor with a command like:
C:\docs\prog\c>text rheathfield.c
It pops up its own window leaving my shell window intact. That's the
way I like it.

Even when I am forced to use terminal-based screen editors I usually
still open up another terminal window for the editor so that I can
switch from shell prompt to editor quickly without having to close
the editor.
 
R

Randy Howard

I just hope nobody here has an automated sawmill.

Well, that computer controlled minigun from an Aegis missile cruiser
we're working on in the lab may not take kindly at all to a clear screen
command.
 
L

Lew Pitcher

Andrew said:
Try using the following:

#define CLRSCRN fprintf ( stdout,"\033[J" )

When you want to clear the screen, all you need to do is

CLRSCRN;

My Volker Craig VC4404 just went into INSERT mode, and displayed a bunch of
funny characters. OTOH, my ASR33 teletype just printed [J

Oh, and it didn't do anything for my 3277 display.


--
Lew Pitcher

Master Codewright and JOAT-in-training
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
 
D

Dan Pop

In said:
CBFalconer wrote:
(snip)

Is that a true, out-of-the-dictionnary english word ? (sorry, I don't
have my english dictionnary with me - she went to bed early tonight !-)

What is a "dictionnary"? ;-) And English is *always* spelled with a
capital E.

Before pointing out other people's typos/misspellings, check yours!

The proper spellings are "imbecilic" and "dictionary".

Dan

P.S. http://www.m-w.com seldom goes to bed ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top