screen clearing in ANSI C

S

sq

"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

sorry ,I do not know~
 
B

Becker

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 know a little about it. There seems to be no such an ANSI function to
do this kind of work.
The function "system("cls")" just calls the shell to execute that
command. So the shell command inside that function is system specific.
"cls" is probably used in MS-DOS. And therefore, "clear" is for most
UNIX/Linux like systems. It's just shell command:)
 
R

rhle.freak

ive been using system("cls")
works fine on my windows system but i think it wont wrk on a linux box
bcoz its a shell command for Dos!!
 
S

santosh

rhle.freak said:
ive been using system("cls")

You've been playing dice.
works fine on my windows system
but i think it wont wrk on a linux box
bcoz its a shell command for Dos!!

Why don't you try Linux and find out instead of silly assumptions?
 
S

santosh

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");
.
.
.
}

Completely non-portable. Assumes the existence of a host system, a
command called 'cls' and that the said command clears the screen, no
more no less.
This syntax is what I have been using over the years, however, you have
to find the proper spot to place this syntax.

It's a call to a function, not a syntax.
 
S

santosh

(e-mail address removed) wrote:

Your reply should ideally be in between or after the quoted text, as
otherwise, it affects the reading order for other posters.
Richard said:
(e-mail address removed) said:
Leslie Kis-Adam wrote:
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.

Then your Lunix doesn't support ANSI escape codes

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

Nor does standard C. Why make your program needlessly non-portable,
especially given that clearing the screen is not important to most
console programs?
 
C

Chris Thomasson

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

:O Sue him!

lol...
 
R

Richard Heathfield

santosh said:

Why make your program needlessly non-portable,
especially given that clearing the screen is not important to most
console programs?

C isn't only useful for console programs, and clearing a screen (or, more
commonly nowadays, a window) can be a useful thing to do. It is not
unreasonable to ask whether an ISO C method exists (although of course we
know the answer is that it doesn't, and that an implementation-specific
method will need to be used).

Yes, you're right that a great many people seem to delight in clearing the
screen for no particularly good reason. But the OP *might* have a good
reason for asking - you never know your luck! - so the best thing to do, I
suppose, is simply to explain the fact that the method will vary from
system to system, so he should abstract out the non-portable functionality
into a separate function, and then write various versions of that function
on an implementation-by-implementation basis.
 
M

Malcolm

Richard Heathfield said:
santosh said:



C isn't only useful for console programs, and clearing a screen (or, more
commonly nowadays, a window) can be a useful thing to do. It is not
unreasonable to ask whether an ISO C method exists (although of course we
know the answer is that it doesn't, and that an implementation-specific
method will need to be used).

Yes, you're right that a great many people seem to delight in clearing the
screen for no particularly good reason. But the OP *might* have a good
reason for asking - you never know your luck! - so the best thing to do, I
suppose, is simply to explain the fact that the method will vary from
system to system, so he should abstract out the non-portable functionality
into a separate function, and then write various versions of that function
on an implementation-by-implementation basis.
What I need is a function that will clear my desk.
 
R

rhle.freak

i dont giv a damn.i know it wont wrk ..its a shell command for dos ,not
for linux :-x!!
 
L

lane straatman

Nelu said:
You should provide some context when replying. This is not Google
Groups. This is Usenet.
I thought that giving context coming at usenet through google would be
hard. It is not.
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?
Just another reason to steer clear of linux. LS
 
M

Mark McIntyre

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

-bash: cls: command not found

(note: posting system-specific responses in CLC will get you flamed).

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

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

You know this is a FAQ, right?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
N

Nelu

lane said:
Just another reason to steer clear of linux. LS

My argument was that what he did was implementation dependent and
it was not off-topic. I hope your argument was intended as a
joke, otherwise you're just trolling and I wasted my time replying.
 
R

Richard Heathfield

lane straatman said:
Just another reason to steer clear of linux.

Yes. It's also just another reason to steer clear of Macs, mainframes,
minicomputers, games consoles, set-top boxes, microwave ovens, and indeed
just about anything that has some kind of display screen but which doesn't
happen to run MS-DOS or Windows. Your world is tiny, but it's safe.
 
M

Malcolm

lane straatman said:
Just another reason to steer clear of linux. LS
Absolutely. Join my campaign for 64-bit ints.

One world,
One race,
One true religion
One vision.

One OS, one way of representing integers.
 
M

Malcolm

Dan Henry said:
It simply can't be done in ANSI C. The most portable and reliable
method is to remove power.
A friend of mine wrote an adventure featuring an LCD laptop with a run-down
battery and the last inputs frozen on the screen.
 
S

santosh

Malcolm said:
Absolutely. Join my campaign for 64-bit ints.

One world,
One race,
One true religion
One vision.

One OS, one way of representing integers.

.... and One Standard for C.
Oops, which one?
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top