473,805 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2312
"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
6865
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 users use vi and more, but I would like to add unicode support to the script. I would not like to force them to open X-sessions in order to show Multilanguage characters. Should I create python shell or is there any other way ?
2
1541
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 encoding is ascii, yet the terminal encoding is latin1 (or cp1252 or whatever, but not ascii). This means that print '£' works fine, yet unicode('£') will raise the UnicodeDecodeError. However print u'£' will also work fine. (Under pythonce this...
1
1823
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(); window.print(); This is the normal way to print a specific frame from a website. Our client works on a SBS2003 with Terminal Server and when they hit the button all frames are printed out, not just the selected one. At first I thought that
11
2478
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
31959
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 Printing.PaperSize("sdfgsfdg", 850, 1100)
29
3530
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 range(128) >>>
5
5113
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
1053
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 printer and also view its properties. If I have the user login to the other terminal server, they can print and view the properties of that printer without a problem. Whenever this print issue happens, it is always the same user on the same...
2
1607
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) knowledge of unicode: string types. What I don't understand yet is what encodings are and when you'd want/need to use them. What I'd like is to just be able to
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9179
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.