Reputation: 73
I have a program that transfers a file written in C. I wanted to give the user some feed back on how much bytes and/or percentage has been transferred. My codes does something like this:
Transferring......100 bytes.
Transferring......200 bytes.
Transferring......300 bytes.
Transferring......400 bytes.
Transferring......500 bytes.
Transferred Complete!!!
As you can see, if I transfer a large file it'll print a bunch of lines. Is it possible to have the number of bytes updates and change without printing another line?
Thanks in advance guys!
Upvotes: 1
Views: 351
Reputation: 2469
If you're writing a win32 application, you can manipulate the position of the cursor with the SetConsoleCursorPosition(HANDLE, COORD)
method to overwrite specific characters:
http://msdn.microsoft.com/en-us/library/ms686025(v=VS.85).aspx
Upvotes: 0
Reputation: 239041
There's no way to do this generically in standard C - after all, the output of your program might be going directly to a line printer.
However, on many terminals you can print a \r
character to return the cursor to the beginning of the current line (or print a number of \b
backspace characters to erase characters one-by-one).
Upvotes: 2