Thread: malloc ,calloc code problem..

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    much better
    thanks

  2. #17
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    what mean this part of the printf

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

    and there is a space after a comma
    what this thing does?

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Look up format specifiers in your textbook, there under printf. Everything else in the quotes just gets printed normally. (The last quote is just the end of your quotes.)

  4. #19
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i cant find stuff on that
    i looked in the formal
    http://www.cplusplus.com/reference/c...io/printf.html

    i cant see there this %05.5f, " stuff

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by transgalactic2 View Post
    i cant find stuff on that
    i looked in the formal
    http://www.cplusplus.com/reference/c...io/printf.html

    i cant see there this %05.5f, " stuff
    Since it is listed there at the top of the page, that's a problem.
    f Decimal floating point
    0 Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier).
    (number) 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.
    .number For e, E and f specifiers: this is the number of digits to be printed after the decimal point.

  6. #21
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Here's a tip, when somebody does get some advice wrong, there will probably someone posting to to correct them fairly promptly.
    If a post has gone unchallenged for a while, and is even backed up by someone else, it's a pretty safe bet that it's correct.
    If you suspect some advice was incorrect, just ask for someone else to confirm.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #22
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    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

    ??

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Read it again:
    .number For e, E and f specifiers: this is the number of digits to be printed after the decimal point.
    There will be five digits printed after the decimal point.

  9. #24
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    it says there

    %[flags][width][.precision][length]specifier

    but in my printf i get the flag at the last place

    ??

  10. #25
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Eh? Your flag was 0, your width was 5, your precision was 5, you didn't have a length, and your specifier was f.

  11. #26
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    can you rephrase this line
    "0 Left-pads the number with zeroes (0) instead of spaces, where padding is specified (see width sub-specifier)."

    i cant understand the meaning of this padding thing
    ?

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If we use %d as an example:
    Code:
    printf("%5d\n", 123);
    printf("%05d\n", 123);
    would produce the output of:
    Code:
      123
    00123
    So in the first example, it gives you spaces to make a length of five, in the second case, it uses 0 to fill the length.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #28
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    so when there is no char between the % and 5
    it put blank spaces?

  14. #29
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by transgalactic2 View Post
    so when there is no char between the % and 5
    it put blank spaces?
    Yes.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  15. #30
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Can I just recommend that you read a book? There are some fine pieces of programming literature recommended on the thread aptly entitled C Book Recommendations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with my morse code program
    By justin87 in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2007, 05:23 PM
  2. Problem compiling simple code examples
    By Wintersun in forum Windows Programming
    Replies: 8
    Last Post: 08-14-2007, 10:30 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM