Thread: Re-writing the same line

  1. #1
    Registered User
    Join Date
    May 2006

    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:
    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?


  2. #2
    Registered User
    Join Date
    Aug 2005
    printing backspaces ( char 9 ) might help.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

  4. #4
    Registered User
    Join Date
    May 2006
    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, 11:10 PM
  4. Replies: 5
    Last Post: 03-16-2003, 05:58 PM
  5. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM