screen clearing in ANSI C

L

Leslie Kis-Adam

Hi everyone!
Does anyone know, if it is possible to clear the screen in ANSI C?
If it is,then how?
Any help would be appreciated.

Laszlo Kis-Adam
<dfighter_AT-NOSPAM_freemail.hu
 
I

Ian Collins

Leslie said:
Hi everyone!
Does anyone know, if it is possible to clear the screen in ANSI C?

No, "screens" are platform specific and may not even exist in many.
 
S

stasgold

Leslie said:
Hi everyone!
Does anyone know, if it is possible to clear the screen in ANSI C?
If it is,then how?
Any help would be appreciated.

Laszlo Kis-Adam
<dfighter_AT-NOSPAM_freemail.hu

printf(" \033[2J");

should do the work, it's an ansi code for clear screen
 
R

Richard Heathfield

(e-mail address removed) said:
Hi everyone!
Does anyone know, if it is possible to clear the screen in ANSI C?
If it is,then how?
Any help would be appreciated.

Laszlo Kis-Adam
<dfighter_AT-NOSPAM_freemail.hu

printf(" \033[2J");

should do the work, it's an ansi code for clear screen

I wrapped it up in a main and ran it on my Linux box, but the screen didn't
clear. Not even the terminal window cleared.
 
G

gurdz

If I'm not wrong, the simplest method of clearing the screen would be
to use a syntax as shown below
{
..
..
..
system("cls");
..
..
..
}

This syntax is what I have been using over the years, however, you have
to find the proper spot to place this syntax.

kind regards,
Gurdip Singh.
(e-mail address removed) || (e-mail address removed)
 
I

Ian Collins

gurdz said:
If I'm not wrong, the simplest method of clearing the screen would be
to use a syntax as shown below
{
system("cls");

Platform (windows?) specific.
 
R

Richard Tobin

gurdz said:
If I'm not wrong, the simplest method of clearing the screen would be
to use a syntax as shown below
system("cls");

I tried that, but unfortunately the "cls" command on my system means
"clear local storage", and it reformatted all my disks.

-- Richard
 
O

osmium

Leslie Kis-Adam said:
Does anyone know, if it is possible to clear the screen in ANSI C?
If it is,then how?

A for loop containing about 60 '\n's would clear most, but not all,
screens.
 
C

Clark S. Cox III

gurdz said:
If I'm not wrong, the simplest method of clearing the screen would be
to use a syntax as shown below
{
..
..
..
system("cls");
..
..
..
}

This syntax is what I have been using over the years, however, you have
to find the proper spot to place this syntax.

Hmm, when I run the following program, it outputs:
"sh: line 1: cls: command not found"

#include <stdlib.h>

int main()
{
system("cls");
return 0;
}
 
G

Gordon Burditt

Hi everyone!
Does anyone know, if it is possible to clear the screen in ANSI C?
If it is,then how?

Where is the screen on my ASR33 teletype? Or do you mean the metal
screen that keeps flies from getting sucked into the fan on the back of
the CPU unit? For that one, you power down the CPU, remove the screen,
and blast it with a stream of water from a hose to wash the flies off.
 
D

Dan Henry

No, "screens" are platform specific and may not even exist in many.

It simply can't be done in ANSI C. The most portable and reliable
method is to remove power.
 
G

gurdz

system ("cls") works for me....

i will provide you with a simple program that uses it when i get back
on.. right now i gotta head for classes..thats right. classes on
saturday...

kind regards,
Gurdip
 
N

Nelu

gurdz said:
system ("cls") works for me....

i will provide you with a simple program that uses it when i get back
on.. right now i gotta head for classes..thats right. classes on
saturday...

You should provide some context when replying. This is not Google
Groups. This is Usenet.

The request was for ANSI C. Wanna bet that that call won't clear
the screen on my Linux machine even though it will probably
compile correctly?
 
S

stasgold

Then your Lunix doesn't support ANSI escape codes

http://en.wikipedia.org/wiki/ANSI_escape_code

Richard said:
(e-mail address removed) said:
Hi everyone!
Does anyone know, if it is possible to clear the screen in ANSI C?
If it is,then how?
Any help would be appreciated.

Laszlo Kis-Adam
<dfighter_AT-NOSPAM_freemail.hu

printf(" \033[2J");

should do the work, it's an ansi code for clear screen

I wrapped it up in a main and ran it on my Linux box, but the screen didn't
clear. Not even the terminal window cleared.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
 
R

Richard Heathfield

[Top-posting fixed]

(e-mail address removed) said:
Richard said:
(e-mail address removed) said:
Leslie Kis-Adam wrote:
Does anyone know, if it is possible to clear the screen in ANSI C?

printf(" \033[2J");

should do the work, it's an ansi code for clear screen

I wrapped it up in a main and ran it on my Linux box, but the screen
didn't clear. Not even the terminal window cleared.
Then your Lunix
Linux

doesn't support ANSI escape codes

Actually, it does, so that wasn't the problem. There was something *else*
you didn't take into account. But yes, that *might* have been the problem,
mightn't it? So that's at least two problems with your suggested technique,
and I humbly suggest that your suggested technique is therefore not
adequate to the task.
 
R

Richard Heathfield

osmium said:
A for loop containing about 60 '\n's would clear most, but not all,
screens.

For example, it wouldn't clear anything off a non-scrolling terminal. It
wouldn't clear anything off a teletype. It wouldn't clear anything off a
window other than the current window (on a multi-window system). It
wouldn't clear anything off a screen if stdout is not associated with that
screen (which isn't necessarily under the control of the program). In fact,
there are so many ways this won't work that I'm surprised you bother to
suggest it.
 
R

Richard Heathfield

Dan Henry said:
It simply can't be done in ANSI C. The most portable and reliable
method is to remove power.

Peter Seebach may well have serious objections to that suggestion (since he
claims to be a conforming implementation).
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top