how do you print to the same position/line in stdout?
so for instance if you wanted to do a progress meter for the command prompt... how would you update the %age completed at the command prompt?
can't figure it out... thanks in advance.
how do you print to the same position/line in stdout?
so for instance if you wanted to do a progress meter for the command prompt... how would you update the %age completed at the command prompt?
can't figure it out... thanks in advance.
"take the long road.... and walk it."
Use the '\b' character to go back:
Code:#include <stdio.h> #include <windows.h> /* For Sleep */ int main ( void ) { int progress = 0; while ( progress <= 100 ) { printf ( "\b\b\b\b%3d%%", progress++ ); fflush ( stdout ); Sleep ( 100 ); } printf ( "\n" ); return 0; }
My best code is written with the delete key.
nice one.
somebody buy that man a beer.
"take the long road.... and walk it."
Uh oh..Originally posted by dug
nice one.
somebody buy that man a beer.
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers
Yeah. Duck and Cover!!!Originally posted by MrWizard
Uh oh..
You can also use \r to return to the beginning of the line.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
>You can also use \r to return to the beginning of the line.
That isn't as flexible though. Most of the time you would prefer to have a format such as this:
'\r' doesn't give you the ability to do that unless you want to continually rewrite the part of the message that remains constant. This would be a waste and may result in flashiness (the bad kind).Code:Percent complete: 10%
>Uh oh..
>Yeah. Duck and Cover!!!
My best code is written with the delete key.
dug, in case you're wondering what all the stupid responses are about, prelude is a woman.
But someone can buy that woman a beer if her husband doesn't mind.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
No, it's not as flexible, but it definitely has its uses. For example a progress bar instead of a percentage. It's much harder with \b whereas \r would be much easier.Originally posted by Prelude
>You can also use \r to return to the beginning of the line.
That isn't as flexible though. Most of the time you would prefer to have a format such as this:
Code:Percent complete: 10%
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
a thousand pardon's prelude...
and thanks for your help.
"take the long road.... and walk it."