Re: [LIP] How does mplayer or wget display their output??

Binand Sethumadhavan <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
Vardhman Jain posted in linux-india-programmers:
> the command was given, so I believe they donot use ncurses. can some
> one tell me how to achieve a similar output(refreshing the same line
> on console on update).

Just use "\r" at the end of the line instead of the "\n", to get the
effect of a carriage-return only (not a line feed).

This code snippet will keep updating the same line:

for (i = 0; i < 100; i++) {
	printf ("%d\r", i);
	fflush(stdout);
	sleep (1);
}

Of course, line buffered streams (like stdout to tty) are guaranteed
to be cleared only on \n, so you need those fflush() calls.

Binand

-- 
Hanlon's Razor: Never attribute to malice that which can be adequately
explained by stupidity.
Bruce's Razor: Never attribute to stupidity that which can be adequately
explained by Microsoft funding.


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.