473,396 Members | 2,068 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.

printing the same spot in the terminal

Hi!

Im looking for a (relatively) easy way to print at the same spot on the
terminal. Like i.e wget does when showing the progressbar and the
percentage of the download.

if been looking in the source code to wget, but it seems very
comprehensive.

printf normally "scrolls" this is what I want to control.

i've tried manipulating the stdout stream with lseek() and fseek() to
rewind, but this doesn't seem to work. the fileposition ftell() returns -1 :(

anyone, any ideas?

/Jacob
Nov 14 '05 #1
2 2294
"Jacob Kjaergaard" <jk****@kom.aau.dk> writes:
Im looking for a (relatively) easy way to print at the same spot on the
terminal. Like i.e wget does when showing the progressbar and the
percentage of the download.


If you're writing to a display device (like a terminal), you can use the
'\b' and '\r' control characters, which are intended to return to the
previous writing position and the beginning of the line, respectively.
#include <stdio.h>

int main (void)
{
int i;
for (i = 1; i <= 100; ++i)
{
/* do 1/100th of something */
printf ("\r%3d%% completed...", i);
fflush (stdout);
}
putchar ('\n');
return 0;
}
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #2
"Jacob Kjaergaard" <jk****@kom.aau.dk> wrote:
Im looking for a (relatively) easy way to print at the same spot on the
terminal.


Then you need to study the ancient and now sadly almost lost art of
FAQ-reading.

In fact, you should've done so to begin with.

<http://www.eskimo.com/~scs/C-faq/q19.4.html>.

Richard
Nov 14 '05 #3

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

Similar topics

4
by: Pekka Niiranen | last post by:
Hi, I have a multiuser script, that I would like to convert to Python. The users open simultaneous telnet -sessions from win2000 to an unix machine and possibly edit unicode textfiles. Currently...
2
by: Fuzzyman | last post by:
How does the print statement decode unicode strings itis passed ? (By that I mean which encoding does it use). Under windows it doesn't appear to use defaultencoding. On my system the default...
1
by: Richard Brand | last post by:
We run into a strange problem with a client when printing a frame from a website. On the site there is a button that performs the following javascript code: parent.myFrame.focus();...
11
by: IC_Clearly | last post by:
I'm running Server 2003 and wonder how well WTS works when printing an Access report to a client. Any suggestions would be appreciated. Thanks. IC
3
by: D Witherspoon | last post by:
No matter what I do the default paper size is always either A3 or 11 by 8.5 .. Here is the code. Dim dlg As DialogResult pd.DocumentName = "Weld Image" Dim pkPaperSize As New...
29
by: Ron Garret | last post by:
>>> u'\xbd' u'\xbd' >>> print _ Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in position 0: ordinal not in...
5
by: HMS Surprise | last post by:
I want to print a count down timer on the same line. I tried print '\r', timeLeft, which just appends to the same line. thanx,
0
by: mcfly1204 | last post by:
We run terminal services on two different win 2k3 servers. The majority of our printers are installed on the AD running win 2k. Periodically one user will lose the ability to print to a particular...
2
by: David | last post by:
Hi list. I've never used unicode in a Python script before, but I need to now. I'm not sure where to start. I'm hoping that a kind soul can help me out here. My current (almost non-existant)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.