By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

question concerning screen control

P: n/a
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?

What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?

Please enlighten me, thanks for your time.
Nov 14 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
In <45**********************@news.mindlink.netKenne th Lantrip <bo********@cmaaccess.comwrites:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?
If you're *really* talking about standard C, then no. Standard C has no
concept of a "screen".

If you're willing to be somewhat non-portable, your compiler might have
a clrscr() function.
What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?
They're fairly standard, yes. I'd try googling for "ansi escape
sequences."

Or if there is a "curses" package available for your platform, you
might use that.

--
John Gordon "... What with you being his parents and all,
go****@panix.com I think that you could be trusted not to shaft
him." -- Robert Chang, rec.games.board

Nov 14 '06 #2

P: n/a
Kenneth Lantrip <bo********@cmaaccess.comwrites:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?
No. See the comp.lang.c FAQ, <http://www.c-faq.com/>, question 19.4.

A formfeed character, '\f', will *not* clear the screen on many
systems.

--
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 14 '06 #3

P: n/a
>My question is: Is there a generally accepted way to clear the screen
>and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?
Not in Standard C. A number of systems have the "curses" library
which deals with this.
>What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?
ANSI control codes only work if the serial terminal or emulation
thereof honors them. So if the program is running on a computer
connected to a dialup line, you're out of luck if the guy is dialing
up with an ASR 33 Teletype or some kind of CRT without ANSI codes.
Also, the terminal emulation in the MS-DOS console is pretty crude
and doesn't do ANSI control codes unless you load ANSI.SYS.

The curses library depends on the user telling the library what type of
terminal it is using, and matching it to a description of the control
codes to use, and the library adapts accordingly.

Lots of terminal emulators emulate ANSI codes. If you *must* hardcode
escape sequences, those are the ones to use. That's not saying much.
>Please enlighten me, thanks for your time.

Nov 15 '06 #4

P: n/a
go***********@burditt.org (Gordon Burditt) writes:
>>My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?

Not in Standard C. A number of systems have the "curses" library
which deals with this.
<OT>
curses is probably overkill if all you want to do is clear the screen.
In some modes of operation, a program that uses curses will restore
the screen's previous contents on exit (though you can probably avoid
that).
--
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 15 '06 #5

P: n/a
Kenneth Lantrip wrote:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?
Not within standard C, no. You might try printing a formfeed character,
'\f', or several newlines, but these are all half-baked solutions.
Again, there's no way to move the cursor to a particular line, without
making a lot of unwarrented assumptions.
What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?
They're fairly widespread but are by no means guarenteed to be present.
Please enlighten me, thanks for your time.
If you're program _really_ needs screen control, then using the curses
package is a good option. It's widely implemented across UNIXes,
Windows and Mac. It is a better option than using ANSI control
sequences, which are lower level. Of course, for a specific platform,
often better, more feature-rich libraries are available, but you'll
have to ask such questions in more specific newsgroups.

Nov 15 '06 #6

P: n/a
John Gordon <go****@panix.comwrote:
In <45**********************@news.mindlink.netKenne th Lantrip <bo********@cmaaccess.comwrites:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?

If you're *really* talking about standard C, then no. Standard C has no
concept of a "screen".

If you're willing to be somewhat non-portable, your compiler might have
a clrscr() function.
s/somewhat/more than somewhat/.
What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?

They're fairly standard, yes. I'd try googling for "ansi escape
sequences."
And don't be surprised when people turn that feature off because it can
be used to aggravate, and then tell you that your program looks crap and
leaves random letters all over the screen.
Or if there is a "curses" package available for your platform, you
might use that.
That's probably the solution most likely to work in many places. At
least it has been ported a lot.

Richard
Nov 15 '06 #7

P: n/a
Kenneth Lantrip <bo********@cmaaccess.comwrites:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?
Apart from the fact that there's no really portable way to do this,
consider whether you really want to clear the screen. If your
application really needs to take control of the screen (like, say, a
text editor), that's fine, and you probably want to use something
similar to curses. But don't clear the screen just for the sake of
clearing the screen; I don't want *your* program to erase *my*
information without a good reason.

(The fact that you asked about moving the cursor indicates that this
likely doesn't apply to what you're doing, though.)

--
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 15 '06 #8

P: n/a
Keith Thompson wrote:
Kenneth Lantrip <bo********@cmaaccess.comwrites:
>>My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?


Apart from the fact that there's no really portable way to do this,
consider whether you really want to clear the screen. If your
application really needs to take control of the screen (like, say, a
text editor), that's fine, and you probably want to use something
similar to curses. But don't clear the screen just for the sake of
clearing the screen; I don't want *your* program to erase *my*
information without a good reason.

(The fact that you asked about moving the cursor indicates that this
likely doesn't apply to what you're doing, though.)
Thanks guys, You all have been most helpful.

I'll give the \f a try. I just wanted to keep the compiling as simple
as possible. I can already use the ncurses library. I was just trying
to get away from any any extra add-ons to make a simple program work.

For what I am about to attempt I will just use the ncurses. I was just
reaching for something more built in so the program would have greater
chance of being operable accross platforms. Scrolling the screen is
out. There is way too much data that needs to be constantly updated for
scrolling. A simple cursor locating would have been nice, as I wouldn't
have to clear your data first.

Oh well, so goes the wishing.
Nov 15 '06 #9

P: n/a
Kenneth Lantrip wrote:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?

What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?

Please enlighten me, thanks for your time.
Spamming won't help your cause. You've already been sufficiently
answered from within the topicality constraints of this group. What's
the point in duplicating your original post without specifying further
details or including code?

Nov 15 '06 #10

P: n/a
santosh wrote:
Kenneth Lantrip wrote:
My question is: Is there a generally accepted way to clear the screen
and perhaps move the cursor to a new location (other than newline) for
the next printf in standard c?

What about ANSI control codes? Are those standard across most
platforms? Or is that just for PC/MAC based computers? Anyone know
where I can see a list of ANSI codes?

Please enlighten me, thanks for your time.

Spamming won't help your cause...
<snip>

My sincere apologies to Kenneth Lantrip. From here the original post
appeared to have been duplicated. Hence my admittedly acidic response.

Nov 15 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.