Implementing a Progress messages

This is a discussion on Implementing a Progress messages within the C Programming forums, part of the General Programming Boards category; How do i implement a progress message that looks like this: [------------- ]60% In a windows 32 console application. I ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    5

    Implementing a Progress messages

    How do i implement a progress message that looks like this:
    [------------- ]60%

    In a windows 32 console application. I am using visual studio 8 for development. I am sure yall must have had to do it sometime, I just couldnt find the code anywhere. Thanks in advance

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Example:
    Code:
    printf("\r[%*s]%d", number_of_dashes, array_holding_a_bunch_of_dashes, percentage);
    Last edited by master5001; 09-19-2008 at 02:38 PM. Reason: Just for you, C_ntua

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by master5001 View Post
    Example:
    Code:
    printf("\r[%*s]%d, number_of_dashes, array_holding_a_bunch_of_dashes, percentage);
    Of course adding the " missing from the above. And you will need the symbol % at the end since you want percentage.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    http://msdn.microsoft.com/en-us/libr...66(VS.71).aspx

    The width argument is a nonnegative decimal integer controlling the minimum number of characters printed.
    So it will not cut the string

    If you want to cut the string printing only part of it - use precision http://msdn.microsoft.com/en-us/libr...14(VS.71).aspx
    s format - The precision specifies the maximum number of characters to be printed. Characters in excess of precision are not printed.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You should do something more like this...

    Example:
    Code:
    const char dashes[] = "----------";
    const char blanks[] = "          ";
    float progress = 0.0f;
    
    printf("\r[%*s%*s] %f%%",
      (int)((100.0 - progress)/10.0), dashes,
      (int)((100.0 - progress)/10.0), blanks, progress);
    Last edited by master5001; 09-19-2008 at 02:40 PM.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    You should do something more like this...
    you hanvn't tested it? Use precision instead of width
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Nope, I didn't test it since I am not even at my computer and he is a big boy... I am just trying to create the whole effect in one function call instead of a call to sprintf() and printf().

  8. #8
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by master5001 View Post
    You should do something more like this...

    Example:
    Code:
    const char dashes[] = "----------";
    const char blanks[] = "          ";
    float progress = 0.0f;
    
    printf("\r[%.*s%.*s] %f%%",
      (int)((100.0 - progress)/10.0), dashes,
      (int)((100.0 - progress)/10.0), blanks, progress);
    So you have to add the two dots

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Oh cripes, I didn't even notice I had done that. I was wondering why vart was asking me that... heh... Copy and paste gone awry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Spy++ view messages posted/sent to a control, or from it?
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 06-24-2007, 11:07 PM
  2. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 12:27 PM
  3. Creating a progress window
    By Xzyx987X in forum Windows Programming
    Replies: 6
    Last Post: 10-06-2004, 04:02 PM
  4. progress bar newbie
    By WaterNut in forum Windows Programming
    Replies: 18
    Last Post: 08-09-2004, 01:42 PM

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