Re-writing the same line

This is a discussion on Re-writing the same line within the C Programming forums, part of the General Programming Boards category; I've written a small file server/client for *nix and I'm just clearing the rough edges: The program reports the percentage ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    2

    Re-writing the same line

    I've written a small file server/client for *nix and I'm just clearing the rough edges:
    The program reports the percentage of the file that has been transfered but it writes a new line every time it refreshes the value like this:
    "11%
    22%
    34%
    ..."
    My doubt is how do I make it simply "update" the value without creating an new line (I know curses would probably do it,even though I've never used it) but this is a very tiny program and it would get "bloated" if I had to include the whole curses library, plus I only want to use that particular feature.

    Any suggestions?

    Thanks!

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    printing backspaces ( char 9 ) might help.
    Kurt

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    printf("%02d%%\b\b\b", percentage);
    fflush( stdout );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    2
    Doh! Didn't know you could "print" backspaces...
    Silly me, thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Imposing Line Numbers automatically in the C code
    By cavestine in forum C Programming
    Replies: 14
    Last Post: 10-15-2007, 12:41 AM
  2. reading a text file printing line number
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-16-2005, 10:31 AM
  3. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 10:10 PM
  4. Replies: 5
    Last Post: 03-16-2003, 04:58 PM
  5. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 03:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21