Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Printf question

  1. Oct 21, 2008 #1
    what mean this part of the printf

    Code (Text):

     printf("calloc1[%d] holds %05.5f, ", i, calloc1[i]);
    Code (Text):

    %05.5f, "
    there is %05.5f
    whats that?

    and there is a space after a comma
    what this thing does?
    Last edited: Oct 21, 2008
  2. jcsd
  3. Oct 21, 2008 #2


    User Avatar

    You first question: %05.5f means that a total field of 5 characters,and use Zero pad, and the last 5 will hold the decimal part.
    Google search give a lot of result:
    see here: http://www.cplusplus.com/reference/clibrary/cstdio/printf.html

    "a space and a comma" means this will output directly.

    Can you test your code?
  4. Oct 22, 2008 #3
    this is th output of the printf line:
    Code (Text):

    calloc1[0] holds 0.00000, malloc1[0] holds -431602080.00000
    i cant see your words in this output

    can you mark those part or something?
  5. Oct 22, 2008 #4


    User Avatar

    calloc1[0] holds 0.00000
    the dot "." For e, E and f specifiers: this is the number of digits to be printed after the decimal point.
    so, there are five zeros.
  6. Oct 22, 2008 #5
    ok 0.5 means persition till the 5th place

    but there 5.5

    whats the other 5 for?
  7. Oct 22, 2008 #6


    User Avatar

    The First "5" means : Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.

    All the words I copied from the referenced web page I suggest.
  8. Oct 22, 2008 #7
    so the first 5 means that we need to print at least five chars in this float number
    and the second 5 means to print the float number in persition 5 place after the point
  9. Oct 22, 2008 #8


    User Avatar

    Yes, you are right.
  10. Oct 22, 2008 #9
    there is a space after a comma
    what this thing does?
  11. Oct 22, 2008 #10
    it says there


    but in my printf i get the flag at the last place
  12. Oct 22, 2008 #11


    User Avatar

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Printf question
  1. Printf debugging (Replies: 3)

  2. Randomization Question (Replies: 4)