473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

screen clearing in ANSI C

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
Nov 24 '06
65 8515
On Mon, 27 Nov 2006 08:26:53 +0000, in comp.lang.c , Chris Hills
<ch***@phaedsys.orgwrote:
>
If yopu have a screen you will need to clear it at some point.
Really? If I did that, all the icons, mouse pointer, menu and desktop
would vanish and I'd be unable to use my pc any more.
>What to you meed by "needlessly non-portahble? The only way o0f making
it completely portable is having no screen.
Or not clearing it.
--
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
Nov 27 '06 #51
On Mon, 27 Nov 2006 08:28:09 +0000, in comp.lang.c , Chris Hills
<ch***@phaedsys.orgwrote:
>In article <4s************@mid.individual.net>, osmium
<r1********@comcast.netwrites
>>"Leslie Kis-Adam" writes:
>>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.

That is not a"clear screen."
Yes it is.
--
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
Nov 27 '06 #52
"Leslie Kis-Adam" <df******@freemail.huwrote in message
news:ek**********@rs18.lvs.iif.hu...
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.
I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.

#include <stdio.h>

char s[] = {27, '[', '2', 'J', 0};

int main(void)
{
printf("%s", s);
}

A list of some commands is here:

http://www.cs.utk.edu/~shuford/termi...rence_card.txt

Searching by VT100 will turn up more.

Nov 27 '06 #53
"David T. Ashley" <dt*@e3ft.comwrites:
"Leslie Kis-Adam" <df******@freemail.huwrote in message
news:ek**********@rs18.lvs.iif.hu...
>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.

I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.
This is exactly why off-topic questions should not receive
answers: often, the given "answers" are wrong.

In the Unix world, the shell has nothing to do with terminal
emulation.
--
Here's a tip: null pointers don't have to be *dull* pointers!
Nov 27 '06 #54
In article <87************@blp.benpfaff.org>,
Ben Pfaff <bl*@cs.stanford.eduwrote:
>I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.
>In the Unix world, the shell has nothing to do with terminal
emulation.
I think that was just a mistake of terminology, rather than being
substantively wrong. After all, Sun's first terminal emulator was
called "shelltool".

I am somewhat suspicious of a program that wants to clear the screen.
If it wants to take over the whole screen, perhaps for editing, then
it's probably going to need a lot more than screen-clearing. If it
isn't doing that, then is it *really* necessary to clear the screen?
Too many programs do it unnecessarily, erasing possibly useful
information for the sake of neatness. So I would advise the OP to
consider whether it's really needed.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 27 '06 #55
"Ben Pfaff" <bl*@cs.stanford.eduwrote in message
news:87************@blp.benpfaff.org...
"David T. Ashley" <dt*@e3ft.comwrites:
>"Leslie Kis-Adam" <df******@freemail.huwrote in message
news:ek**********@rs18.lvs.iif.hu...
>>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.

I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.

This is exactly why off-topic questions should not receive
answers: often, the given "answers" are wrong.
Non-sequitur: even if the question were on-topic, there is no guarantee I
would have answered it correctly.

Additionally, my answer is "right". The short program will clear the screen
using Putty and probably also using SSH Secure Shell.

I also pointed the original poster to VTXXX materials ... a starting point.

I'm not sure there is a single method that will clear the screen on all
platforms.
In the Unix world, the shell has nothing to do with terminal
emulation.
That is like claiming that traffic lights have nothing to do with
automobiles ...

The shell (bash or similar) usually [ultimately] interacts with the user via
some kind of terminal emulator ... terminal emulation comes into it quite
quickly unless you only output and input sequential lines of text.

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

Nov 28 '06 #56
David T. Ashley wrote:
"Leslie Kis-Adam" <df******@freemail.huwrote in message
news:ek**********@rs18.lvs.iif.hu...
>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.

I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.

#include <stdio.h>

char s[] = {27, '[', '2', 'J', 0};

int main(void)
{
printf("%s", s);
}
No. Unix shells do not emulate terminals. None of sh, ksh or csh knows
about terminals. You have to tell them through systems such as termcap
or terminfo.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 28 '06 #57
In article <ZN************@fe19.usenetserver.com>,
David T. Ashley <dt*@e3ft.comwrote:
>"Ben Pfaff" <bl*@cs.stanford.eduwrote in message
news:87************@blp.benpfaff.org...
>"David T. Ashley" <dt*@e3ft.comwrites:
>>I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.
>This is exactly why off-topic questions should not receive
answers: often, the given "answers" are wrong.
>Additionally, my answer is "right". The short program will clear the screen
using Putty and probably also using SSH Secure Shell.
>In the Unix world, the shell has nothing to do with terminal
emulation.
>The shell (bash or similar) usually [ultimately] interacts with the user via
some kind of terminal emulator ... terminal emulation comes into it quite
quickly unless you only output and input sequential lines of text.
Putty contains a terminal emulator, but it is not a shell -- it does
not *itself* parse commands and submit them for execution.
Putty accepts characters and sends them to somewhere else for processing,
and handles received characters, but it is only displayware.

bash and similar may usually interact with a user via some kind of
terminal emulator, but bash etc. do not -provide- that terminal emulator:
they blindly make use of whatever information they have been told about
the characteristics of the terminal emulator that some other layer has
provided.

For example, right at the moment, I am typing this message within
the vi editor (not a terminal emulator), which was invoked by trn
(not a terminal emulator), which I commanded to start from within ksh
(not a terminal emulator), which transmits and receives data over a
pair of network sockets (not terminal emulators) that were created
between a remote rlogind server and a local rlogin client; the rlogin
client was something I commanded to start from within ksh (not a terminal
emulator), which transmits and receives data via an X Windows session
(which knows how to draw pretty graphics but needs to be told where
and what to draw); that X Windows session is being managed by the
4Dwm window manager (which knows more about where to draw various kinds
of things), within which I have started up an Xwsh window that has the
ksh running within it -- and the Xwsh window *is* the terminal emulator.

To recap that, there is something that knows about graphics (X) and
something that knows about styles (4Dwm), and there is a terminal
emulator, Xwsh, which is connected to ksh that I told to rlogin to
another machine, and on the ksh on the other machine I invoked trn
which started up vi which is sending the screen-clear and so on needed
way back at the Xwsh program.

Notice that none of the shells or rlogin (or ssh if I were using that)
are terminal emulators: a different piece entirely was the terminal
emulator -- a piece that would correspond most closely to the Putty
you mentioned. Notice the terminal emulator Xwsh is not any of the
several layers of shells, nor is the terminal emulator any of the
network transport layers.
So... you *were* wrong, shell programs do not emulate any
terminal, and are not responsible for what appears (or not) on the
screen.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Nov 28 '06 #58
Leslie Kis-Adam <df******@freemail.huwrites:
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.
I'm amazed. I see 57 articles in this thread. Only one mentions that
this is a FAQ, and that one didn't say which one.

We have a very good FAQ list for this newsgroup. We should use it,
rather than reinventing the wheel. (And if we must reinvent the
wheel, can we at least make it round?)

The comp.lang.c FAQ is at <http://www.c-faq.com/>. You have asked
question 19.4.

I have a couple of comments on top of that.

The FAQ overstates the portability of using a form-feed character,
'\f', to clear a screen; it doesn't work on most of the terminal
emulators I use.

Consider carefully whether you really need to clear the screen at all.
You'll be erasing information belonging to whomever is using your
program, information that is probably on the screen for a very good
reason. There are good reasons for clearing the screen, but be sure
you actually have a good reason before you do it. (If your program
needs to control the entire screen, like a text editor, you'll need
something much more sophisticated than a control sequence or simple
external program; the details are equally off-topic.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 28 '06 #59

Chris Hills wrote:
In article <4s************@mid.individual.net>, osmium
<r1********@comcast.netwrites
"Leslie Kis-Adam" writes:
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.

That is not a"clear screen."
It's not a banana either, so what? It's about the best (or only) method
available to portably do what the OP requested, since it covers most
cases (depending on detail of what was meant by "clear" and "the
screen", but it works for most common meanings of those terms).

Nov 28 '06 #60
Ben Pfaff said:
"David T. Ashley" <dt*@e3ft.comwrites:
>"Leslie Kis-Adam" <df******@freemail.huwrote in message
news:ek**********@rs18.lvs.iif.hu...
>>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.

I don't know about ANSI ... but in the *nix world most shell programs
emulate the VT100 ... the following program will clear the screen.

This is exactly why off-topic questions should not receive
answers: often, the given "answers" are wrong.
The question is not off-topic, and there is a perfectly topical answer to
the perfectly topical question. That perfectly topical answer is "no".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 28 '06 #61
Chris Hills <ch***@phaedsys.orgwrote:
In article <11*********************@m7g2000cwm.googlegroups.c om>,
santosh <sa*********@gmail.comwrites
st******@gmail.com wrote:
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?

If yopu have a screen you will need to clear it at some point.
Sorry, but that's complete nonsense. Some screens (e.g., dumb terminals)
_cannot_ even be cleared.
You have to use the escape codes for that VT
That, too, is nonsense. It's just one option, and it works far from
everywhere.

Richard
Nov 28 '06 #62
On Mon, 27 Nov 2006 20:07:48 -0500, in comp.lang.c , "David T. Ashley"
<dt*@e3ft.comwrote:
>"Ben Pfaff" <bl*@cs.stanford.eduwrote in message
>>
This is exactly why off-topic questions should not receive
answers: often, the given "answers" are wrong.

Non-sequitur: even if the question were on-topic, there is no guarantee I
would have answered it correctly.
But had you been wrong about something topical, there would be plenty
of people here who could correct you. With an offtopic reply, you may
be utterly wrong, and yet go quite uncorrected.
>Additionally, my answer is "right". The short program will clear the screen
using Putty and probably also using SSH Secure Shell.
Its worth noting that finding examples which happen to agree with you
does *not* constitute a proof. Here's a case in point: I assert that
all inhabitants of my town are named mcintyre. Evidence: all the ones
I can see are named mcintyre. QEND.
>I'm not sure there is a single method that will clear the screen on all
platforms.
There isn't. This is a FAQ by the way.
--
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
Nov 28 '06 #63
On Tue, 28 Nov 2006 01:52:22 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.orgwrote:
>I'm amazed. I see 57 articles in this thread. Only one mentions that
this is a FAQ, and that one didn't say which one.
What, we have to find the /number/ of the FAQ for people too?

Sheesh, why don't we get them a cold beer and sandwich while we're at
it?
--
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
Nov 28 '06 #64
Mark McIntyre wrote:
On Tue, 28 Nov 2006 01:52:22 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.orgwrote:
I'm amazed. I see 57 articles in this thread. Only one mentions
that this is a FAQ, and that one didn't say which one.

What, we have to find the number of the FAQ for people too?

Sheesh, why don't we get them a cold beer and sandwich while we're at
it?

Hook me up, Slim.


Brian
Nov 28 '06 #65
Keith Thompson wrote:
Leslie Kis-Adam <df******@freemail.huwrites:
>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.

I'm amazed. I see 57 articles in this thread. Only one mentions that
this is a FAQ, and that one didn't say which one.

We have a very good FAQ list for this newsgroup. We should use it,
rather than reinventing the wheel. (And if we must reinvent the
wheel, can we at least make it round?)

The comp.lang.c FAQ is at <http://www.c-faq.com/>. You have asked
question 19.4.

I have a couple of comments on top of that.

The FAQ overstates the portability of using a form-feed character,
'\f', to clear a screen; it doesn't work on most of the terminal
emulators I use.

Consider carefully whether you really need to clear the screen at all.
You'll be erasing information belonging to whomever is using your
program, information that is probably on the screen for a very good
reason. There are good reasons for clearing the screen, but be sure
you actually have a good reason before you do it. (If your program
needs to control the entire screen, like a text editor, you'll need
something much more sophisticated than a control sequence or simple
external program; the details are equally off-topic.)
Thanks for posting the existense, and location of the faq. I wanted to
clear the screen for a portable character based go-moku game, but I
found out, that I don't really need it, so decided not to clear. Anyway,
thanks for all help.

--
Leslie Kis-Adam or
Laszlo Kis-Adam or even
Kis-Ádám László

Student
Budapest University of Technology and Economics
Faculty of Electronic Engineering and Computer Science
<dfighter_AT_NOSPAM_freemail.hu>
Dec 2 '06 #66

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Curious Student | last post by:
I was looking at methods of clearing the screen. I remember using clrscr() in C on a Unix machine when I was at the institute learning software development. I tried using it on MS VC++ 6.0. It...
51
by: someone | last post by:
I was just wondering if there is any way of editing anything already printed on the screen with out using the system("cls") command.
11
by: Rajendran | last post by:
I just want to clear the above three lines from the current position, so that I can start printing my results from that point. In short I want to clear a portion of my screen. Note: I work in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.