I want to clear a portion of screen - How??

R

Rajendran

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 the UNIX environment using gcc compiler. And I'm not a
super user.

I want a "simple solution".

I tried the combination of "\r\b" escape sequences. But \b is not
taking me back to the above line?
I urgently need the key for this.
Please help me achieving this.

I daily visit my topic to see whether I got the answer or not!
Thank you.
 
R

Richard Heathfield

Rajendran said:
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 the UNIX environment using gcc compiler. And I'm not a
super user.

Standard C has no solution to your problem. (Standard C does not offer
full-screen addressing.)

I suggest you ask your question in comp.unix.programmer where (I trust) the
experts there will be able to offer you a platform-specific solution.
 
S

Skarmander

Rajendran said:
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.
See question 19.4 in the FAQ: http://www.c-faq.com
Note: I work in the UNIX environment using gcc compiler. And I'm not a
super user.
comp.unix.programmer is your friend.
I want a "simple solution".
The (n)curses library is pretty simple. There's probably not much to gain
from even simpler solutions, since they won't transfer to other platforms,
and learning them is a waste of time.
I tried the combination of "\r\b" escape sequences. But \b is not
taking me back to the above line?

\b is backspace, which "moves the active position to the previous position
on the current line. If the active position is at the initial position of a
line, the behavior of the display device is unspecified." In other words,
you can't use backspace that way and expect it to work.

S.
 
R

Rich Gibbs

Rajendran said the following, on 09/02/06 03:00:
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.

The C language has no standard facilities dealing with the "screen", and
not all implementations have anything that could be so described.
especially said:
Note: I work in the UNIX environment using gcc compiler. And I'm not a
super user.

I want a "simple solution".

A better place to post this question would be comp.unix.programmer.

[OT]
In a Unix/Linux environment, your best bet is probably to use
screen-handling tools contained in the 'ncurses(3)' package. They are
pretty simple to use, and will allow your program to work with a wide
range of display devices.
[/OT]
 
P

Peyman

I'm not quite sure about this, but google for an implementation of
"conio.h" header file, and find the implementation for function
clearScreen() or something like that, it should look something like:
printf("03[4[/j/r"); // roughly to give an idea about how strange it
is!
you might do the thing by a bit of hacking into this code.
but still, comp.unix.programmer is your friend!
 
R

Richard Heathfield

Peyman said:
I'm not quite sure about this, but google for an implementation of
"conio.h" header file,

That advice is not going to do him any good. The probability of there being
a <conio.h> header on his Unix system is vanishingly small, and the
probability that it is useful to him is even smaller.

but still, comp.unix.programmer is your friend!

That advice, however, works fine.
 
R

Rajen

Thanks to all of you!
I already posted this question as you said - on unix.progammer

Finally I started learning ncurses but the example programmes are
giving strange results on my screen. Anyhow ncurses is interesting.

Anyway I "still welcome" your solutions
 
R

Rajen

Hello Peyman,
could you please give me any websites relating to this.
what does /j do? I started searching the net. Reply me.
Thank you.
-Rajen
 
W

W H G

Rajen said:
Hello Peyman,
could you please give me any websites relating to this.
what does /j do? I started searching the net. Reply me.
Thank you.
-Rajen
Peyman said:
I'm not quite sure about this, but google for an implementation of
"conio.h" header file, and find the implementation for function
clearScreen() or something like that, it should look something like:
printf("03[4[/j/r"); // roughly to give an idea about how strange it
is!
you might do the thing by a bit of hacking into this code.
but still, comp.unix.programmer is your friend!

The answer to clearing the screen is to use whatever function
your compiler vendor supplied. If the compiler was meant for
regular computer use it probably has a function - but it is off topic
for this group. RTFM

Ignoring that advice, make sure you have and ANSI screen driver
installed, and look up the codes for it. I went back to MSDOS 4
document. The driver is ANSI.SYS. All the codes start with
an escape character, aka, octal 033, decimal 27 or hex 1B.
Clear the screen is escape [2J so printing that should clear the screen.
puts("033[2J");
I suspect the previous poster worked from memory ( "something like").

------------- W H G
 
R

Rajen

Thanks WHG,
What does RTFM Mean? I came to know the esacpe sequences and I'm
comfortable with them.
esc[4A - Takes the cursor four lines up from current postion
esc[#B - " # lines down "
esc[#C - # columns forward
esc[#D #columns backward
-----------------------------------------------------------------
 
P

Peyman

W said:
Rajen said:
Hello Peyman,
could you please give me any websites relating to this.
what does /j do? I started searching the net. Reply me.
Thank you.
-Rajen
Peyman said:
I'm not quite sure about this, but google for an implementation of
"conio.h" header file, and find the implementation for function
clearScreen() or something like that, it should look something like:
printf("03[4[/j/r"); // roughly to give an idea about how strange it
is!
you might do the thing by a bit of hacking into this code.
but still, comp.unix.programmer is your friend!

The answer to clearing the screen is to use whatever function
your compiler vendor supplied. If the compiler was meant for
regular computer use it probably has a function - but it is off topic
for this group. RTFM

Ignoring that advice, make sure you have and ANSI screen driver
installed, and look up the codes for it. I went back to MSDOS 4
document. The driver is ANSI.SYS. All the codes start with
an escape character, aka, octal 033, decimal 27 or hex 1B.
Clear the screen is escape [2J so printing that should clear the screen.
puts("033[2J");
I suspect the previous poster worked from memory ( "something like").

Yes, exactly, thank you for correcting me, what I meant was:
printf("033[2J");
or as you said, it can be:
puts("033[2J");
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top