Thread: replacing console output

  1. #1
    Lord CyKill

    Unhappy replacing console output

    i want to display a timer in C with sleep function,but the problem is that I want to display the remaining time and then overwrite it after 1 second.How can i overwrite a number that i have already
    dsplayed it on the console and then replace it with another diget?
    I am working in gcc.

  2. #2

    Unhappy hmm

    but when it go to single digit, the units digit is replaced with 0 and the actual unit digit shifts to tens to go from 10 to 9, it turns into 90!

  3. #3
    Registered User
    Join Date
    Mar 2003
    Hi, I am new to the board
    Anyway, you could always do a check for timer. If it's < 10 you print 0%d (that's a zero). If it's > 10, you print %d...

    do {
      if (timer < 10) {
        printf( "\r0%d", timer );
      } else {
        printf( "\r%d", timer );

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Or you could do it the easy way:

    >>printf ("%02d\n", 1);

    The 02 means a minimum field width of 2, filled with leading zeros.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. redirect console output to a String?
    By TwistedMetal in forum C Programming
    Replies: 10
    Last Post: 02-26-2008, 02:54 PM
  2. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 06:41 PM
  3. Help with Console output
    By JeremyCAFE in forum C++ Programming
    Replies: 4
    Last Post: 12-20-2005, 10:36 AM
  4. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  5. Redirecting console output
    By _hannes in forum Windows Programming
    Replies: 3
    Last Post: 11-04-2004, 04:51 AM