%d, %s????

This is a discussion on %d, %s???? within the C++ Programming forums, part of the General Programming Boards category; What do %d, %s and other things like that do, and what are they called?...

  1. #1
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227

    %d, %s????

    What do %d, %s and other things like that do, and what are they called?
    Keyboard Not Found! Press any key to continue. . .

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    well these were used in operations in C...you could still use it in C++, but why would you

    %d is used for ints I believe it stands for "decimal" and %s is used for strings, er char arrays...

    for example:

    Code:
    int x=3;
    char *foo = "bar";
    printf( " this is the number: %d and this is the string: %s", x, foo );
    //prints out: this is the number: 3 and this is the string: bar

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    C style format flags used with I/O routines like printf() and scanf().

  4. #4
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    but how does it kno which number to use and which char array to use?
    Keyboard Not Found! Press any key to continue. . .

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    printf( " this is the number: %d and this is the string: %s", x, foo );

    look at the code DeepFyre, x=3, and foo=bar;

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Code:
    printf( " this is the number: %d and this is the string: %s", x, foo );
    It accepts an "unlimited" number of arguments, by order of where the % operators are used.

  7. #7
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    yea i know that axon, but what if there were more variables?

    >>by order of where the % operators are used.
    so would it use the first number/string it comes upon?
    Last edited by DeepFyre; 09-22-2004 at 09:12 PM.
    Keyboard Not Found! Press any key to continue. . .

  8. #8
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    EDIT:: yes, that is why he said by order

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  9. #9
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Quote Originally Posted by Vicious
    It accepts an "unlimited" number of arguments, by order of where the % operators are used.
    So the first %d in your code will respond to the first argument after the string. And the second %whatever will respond to the second argumentand so on

    [edit]
    ah axon again!

    [edit2]
    Ah all the edits!

  10. #10
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    k, thanks a lot guys!
    Keyboard Not Found! Press any key to continue. . .

  11. #11
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    >>ah axon again!<<

    you know that my middle name is flash_gordon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

Popular pages Recent additions subscribe to a feed

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