Screen Handling

C

Curious Student

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 didn't work.
I looked up the documentation. The documentation said this is a
non-standard function and is included in conio.h. I had included
conio.h already, and yet it couldn't link. I guess clrscr is a unix
thing then?

I also found this code in a book as well as on the Net about clearing
the screen:

THIS CAME FROM A DOWNLOADED SAMPLE
printf("\033[2J"); /* Clear the entire screen. */
printf("\033[0;0f"); /* Move cursor to the top left hand corner */



THIS CAME FROM A BOOK
printf("\x1B[2J");


I also found some documentation saying there was this library called
curses that was very interesting and it dealt with screen handling
functions. I looked it up on Google and found the documentation for
the header curses.h and an overview. But I think I'll also need the
DLL along with the header, so I can use the curses.

My questions are:

(1) Why is it that the phrase "\x1B[2J" should cause the screen to
clear?

(2) Why doesn't it work for me?

(3) Where can I get the necessary files to use curses? Where can I get
some tutorial on using curses, because I saw there was no function to
create a window/console, but there were functions for manipulating
windows (example colorwindow etc.) and they all expected a WINDOW data
type (that's no problem, that's declared in the header, but how do I
fetch a window's. Should I just use the Win32 API GetWindow etc?
Surely, it wouldn't be a Win32 platform specific library - this
curses?).
 
T

Thomas Matthews

Curious said:
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 didn't work.
I looked up the documentation. The documentation said this is a
non-standard function and is included in conio.h. I had included
conio.h already, and yet it couldn't link. I guess clrscr is a unix
thing then?

I also found this code in a book as well as on the Net about clearing
the screen:

THIS CAME FROM A DOWNLOADED SAMPLE
printf("\033[2J"); /* Clear the entire screen. */
printf("\033[0;0f"); /* Move cursor to the top left hand corner */



THIS CAME FROM A BOOK
printf("\x1B[2J");


I also found some documentation saying there was this library called
curses that was very interesting and it dealt with screen handling
functions. I looked it up on Google and found the documentation for
the header curses.h and an overview. But I think I'll also need the
DLL along with the header, so I can use the curses.
Congradulations, you have found out why clearing the screen is not
part of the standard language (and thus not discussed in this
newsgroup). However, it _is_ a FAQ:
http://www.eskimo.com/~scs/c-faq/q19.4.html
My questions are:

(1) Why is it that the phrase "\x1B[2J" should cause the screen to
clear?
Because that is a command for a terminal that supports the
ANSI terminal escape sequences. Different terminals have different
commands to clear the screen. This is what the "curses" library
is based on.

(2) Why doesn't it work for me?
You are probably working with a terminal / window that doesn't
support the ANSI escape sequences.

(3) Where can I get the necessary files to use curses? http://www.google.com
http://www.fsf.org
http://www.sourceforge.org


Where can I get some tutorial on using curses, because I saw
> there was no function to
create a window/console, but there were functions for manipulating
windows (example colorwindow etc.) and they all expected a WINDOW data
type (that's no problem, that's declared in the header, but how do I
fetch a window's. Should I just use the Win32 API GetWindow etc?
Surely, it wouldn't be a Win32 platform specific library - this
curses?).
http://www.google.com, use "curses tutorial".
Perhaps a good book about the Unix operating system.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
D

Dan Pop

In said:
I was looking at methods of clearing the screen.

And you have missed the first reference document you have to read *before*
posting here: the comp.lang.c FAQ.

Dan
 
M

Malcolm

Curious Student said:
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.
Unfortunately there are no ANSI C functions for manipulating the display.
You receive characters from stdin, and send characters to stdout. If you
want to clear the screen, print green text, suppress echoing to input a
password, you must use a platform-specific library.
 
K

Keith Thompson

Malcolm said:
Unfortunately there are no ANSI C functions for manipulating the display.
You receive characters from stdin, and send characters to stdout. If you
want to clear the screen, print green text, suppress echoing to input a
password, you must use a platform-specific library.

<QUIBBLE>

You must write platform-specific code. It may not be necessary to
use a platform-specific library (though that's usually the best
way to do it). For example, the following program:

#include <stdio.h>
int main(void)
{
fputs("\033[1;1H\033[2J", stdout);
return 0;
}

*might* clear the screen on your system (it does on mine); if so, it
does so without using any platform-specific library.

The advantage of using a platform-specific library, of course, is that
you don't have to reinvent the wheel.

</QUIBBLE>
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top