Thread: malloc ,calloc code problem..

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    I'm beginning to smell troll here....

    *(malloc1+i) will return the content of address "i"
    but
    malloc1[i] will return the address "i" itself

    WRONG - they're the same damn thing.

    And neither of them have anything to do with the address of i

    malloc1 is the address
    malloc1[0] is the contents of the first address
    malloc1[1] is the contents of the second address
    *(malloc1+1) is the same as malloc1[1] only written differently
    malloc1[i] is the contents of the i'th address.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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

  3. #3
    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?

  4. #4
    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.)

  5. #5
    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

  6. #6
    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.

  7. #7
    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. #8
    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. #9
    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. #10
    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. #11
    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. #12
    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. #13
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    so when there is no char between the % and 5
    it put blank spaces?

  14. #14
    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. #15
    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