473,386 Members | 1,846 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,386 software developers and data experts.

Line overwriting

I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.
Feb 13 '06 #1
11 5489
In article <pa***************************@sjones.org>,
Steven Jones <sj****@sjones.org> wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


Allow me to be the first to say this - and I say it from the deepness of my
heart, with all the kindness and love one has come to associate with the
helpful posts you get in this newsgroup:

Not portable. Can't discuss it here. Blah, blah, blah.

Feb 13 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


printf("\r"); fflush(stdout);
But, while this will work on most any display device (including hard copy
devices), it is likely to leave output in a mess on most of them.

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)

iD8DBQFD8IgYagVFX4UWr64RAlVaAJsHIcbBegJsQf1pu669Ws BbpAy1lwCg7RBb
bdLqgwKLNM3qDtTvOeU10Vc=
=tvu6
-----END PGP SIGNATURE-----
Feb 13 '06 #3
Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


As already mentioned, this is off topic in this newsgroup. You might
want to have a look at the NCURSES library.
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Feb 13 '06 #4
August Karlstrom wrote:
Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and
then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


As already mentioned, this is off topic in this newsgroup. You might
want to have a look at the NCURSES library.


The question seems entirely topical: "How can I do _X_
in C?" As it happens, the answer is either "You cannot"
(for strict constructionists) or "You need facilities that
are not part of C, but may be available as extensions on
the platforms that interest you" (for people of a helpful
bent). An *extremely* helpful person might even suggest a
look at Questions 19.3 and 19.4 in the comp.lang.c Frequently
Asked Questions (FAQ) list at http://c-faq.com/ -- but that's
*really* going too far, and anyone who did so would be rightly
castigated.

See also "praeterition."

--
Eric Sosman
es*****@acm-dot-org.invalid

Feb 13 '06 #5
Lew Pitcher wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


printf("\r"); fflush(stdout);

But, while this will work on most any display device (including hard copy
devices), it is likely to leave output in a mess on most of them.


Given that he wants to overwrite both lines with two new lines[*], the
above solution won't work.

This comes down to the need to use some sort of extension, perhaps the
curses library, in order to do it. The use of curses (or any other
library which may perform this function) is OT in clc. I'm not sure
where curses is topical.

[*] As opposed to "two newlines". :-)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Feb 13 '06 #6
On Mon, 13 Feb 2006 13:02:44 +0000, Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


You guys are right: This is off-topic in this group. I realized shortly
after posting; my apologies. Anyway, in case anyone is interested, on an
xterm terminal emulator the effect can be achieved with

printf("\x1b[2A") ;

just before (or after) the sleep() call.

Feb 13 '06 #7
Steven Jones wrote:
On Mon, 13 Feb 2006 13:02:44 +0000, Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second,
and then print out two more lines, overwriting the previous two.
The sleeping bit is trivial but, what about the overwriting? I
am assuming that the output will be displayed on a standard
terminal emulator, like xterm.


You guys are right: This is off-topic in this group. I realized
shortly after posting; my apologies. Anyway, in case anyone is
interested, on an xterm terminal emulator the effect can be
achieved with

printf("\x1b[2A") ;

just before (or after) the sleep() call.


Whatever an "xterm emulator" may be, that code won't work unless
the destination falls in the class of ANSI standard CRT terminals
(which are OT here). These are only one of many possible terminal
types, and are the reason why such things as termtype and curses
(both also OT here) were invented.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
Feb 13 '06 #8
Steven Jones wrote:
On Mon, 13 Feb 2006 13:02:44 +0000, Steven Jones wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.
You guys are right: This is off-topic in this group.


As Eric Sosman said, the question is on topic, it's just that the answer
is that you need something beyond standard C.
I realized shortly
after posting; my apologies. Anyway, in case anyone is interested, on an
xterm terminal emulator the effect can be achieved with

printf("\x1b[2A") ;

just before (or after) the sleep() call.


For increased portability look at the various screen handling libraries
such as Curses as others have suggested.
--
Flash Gordon
Living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidlines and intro -
http://clc-wiki.net/wiki/Intro_to_clc
Feb 13 '06 #9
On Mon, 13 Feb 2006 13:02:44 GMT, in comp.lang.c , Steven Jones
<sj****@sjones.org> wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


This is a FAQ - search for entries relating to in-situ altering of
files - but essentially you can't do this in standard C.
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

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 18 '06 #10
Mark McIntyre <ma**********@spamcop.net> writes:
On Mon, 13 Feb 2006 13:02:44 GMT, in comp.lang.c , Steven Jones
<sj****@sjones.org> wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


This is a FAQ - search for entries relating to in-situ altering of
files - but essentially you can't do this in standard C.
Mark McIntyre


I think he's trying to overwrite text on the display, not data in a
file. (You can't do that in standard C either.)

--
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.
Feb 18 '06 #11
On Sat, 18 Feb 2006 20:38:17 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:
On Mon, 13 Feb 2006 13:02:44 GMT, in comp.lang.c , Steven Jones
<sj****@sjones.org> wrote:
I have a C program that prints out two lines as follows:

Line 1
Line 2

What I would like is for this program to sleep for one second, and then
print out two more lines, overwriting the previous two. The sleeping bit
is trivial but, what about the overwriting? I am assuming that the output
will be displayed on a standard terminal emulator, like xterm.


This is a FAQ - search for entries relating to in-situ altering of
files - but essentially you can't do this in standard C.
Mark McIntyre


I think he's trying to overwrite text on the display, not data in a
file. (You can't do that in standard C either.)


Yes, indeed. I see that on rereading it. Its still a FAQ tho - a
search for gotoxy will turn up 19.4

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

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 19 '06 #12

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

Similar topics

6
by: Darren Dale | last post by:
Is there a module somewhere that intelligently deals with reports to the command line? I would like to report the progress of some pretty lengthy simulations, and currently I have the new reports...
6
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd...
19
by: tweak | last post by:
I have been messing around with buffers, and I found it peculiar that the code below will run without a segmentation fault. As far as I know, overwriting the allocated space from a call to...
5
by: Joe Delphi | last post by:
Hi Newbie to VB.Net and I have a question I need to open a text file, read each line, and if I find something in the line, delete that line from the text file. Can anyone tell me how to do...
3
by: Jamiil | last post by:
JavaScipt ~~~~~~~ <script type="text/javascript"> name = new String("My Name"); document.write("<H4>Author: </H4>" + name); </script> I would like the word 'Author:' to be in 4th level...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
6
by: tomtown.net | last post by:
Hello I'm trying to get a single line removed from a text file using a search pattern (pretty simple: if line contains "NODE1") -> remove line). To achieve this I's like to operate with only the...
0
by: dave2071 | last post by:
Hi I am having trouble trying to get the line number for a node from an XML DOM document. Xerces-J has a good example by extending the DOMParser and overwriting the startDocument and startElement...
27
by: Jason | last post by:
Hi, I need to open an existing file, seek to a position at X number of bytes, and write out Y number of bytes overwriting any existing bytes, but no erasing any other data. Is this possible? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.