printinga number while being incrementing on the screen

This is a discussion on printinga number while being incrementing on the screen within the C Programming forums, part of the General Programming Boards category; Hi All How can i print/display a number being incremented on the screen. For example a variable 'i' is being ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    34

    printinga number while being incrementing on the screen

    Hi All
    How can i print/display a number being incremented on the screen. For example
    a variable 'i' is being incremented like this i = i+224, i would like to print this number on the screen while its being incremented something like below:


    224(then 448 etc)

    not like the below:

    224 448 672 etc
    Any help will highly be appreciated
    Regards

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    You may want to try a format such as "\r%d".
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    34
    Quote Originally Posted by Dave_Sinkula View Post
    You may want to try a format such as "\r%d".
    Doesn't this format only display the total incremented number? i dont want to have that....

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Then I have no idea what you are trying to say.
    Last edited by Dave_Sinkula; 03-26-2008 at 11:48 PM. Reason: Added -ing. Oops.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    34
    Quote Originally Posted by Dave_Sinkula View Post
    Then I have no idea what you are try to say.
    An example of what i am trying to accomplish here is, if you install a software and the progress bar increases and the % number being incremented on the screen displaying the % complete of installation. I would like to do something like that, to display the %number being incremented on the screen.

    Regardss

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    That's what I though, which is why I suggested trying this.
    Code:
    #include <stdio.h>
    
    int main()
    {
       int i;
       for ( i = 0; i < 100000 * 224; i += 224 )
       {
          printf("\r&#37;d", i);
       }
       return 0;
    }
    Whether or not that does what you want is up to the command shell to a large degree.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Dave_Sinkula View Post
    That's what I though, which is why I suggested trying this.
    Code:
    #include <stdio.h>
    
    int main()
    {
       int i;
       for ( i = 0; i < 100000 * 224; i += 224 )
       {
          printf("\r&#37;d", i);
       }
       return 0;
    }
    Whether or not that does what you want is up to the command shell to a large degree.
    This will not do it. Most likely!

    First there is no sleep or as such to allow us to see the increment. Then there is no '\n' printed so
    printf will buffer the output and will print unpredictably!
    There should be a sleep, and a flush call to make it work!

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 10:27 AM
  2. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 01:56 PM
  3. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 02:03 AM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 05:25 AM

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