What do %d, %s and other things like that do, and what are they called?
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?...
What do %d, %s and other things like that do, and what are they called?
Keyboard Not Found! Press any key to continue. . .
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
C style format flags used with I/O routines like printf() and scanf().
but how does it kno which number to use and which char array to use?
Keyboard Not Found! Press any key to continue. . .
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
It accepts an "unlimited" number of arguments, by order of where the % operators are used.Code:printf( " this is the number: %d and this is the string: %s", x, foo );
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. . .
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
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 onOriginally Posted by Vicious
[edit]
ah axon again!
[edit2]
Ah all the edits!![]()
k, thanks a lot guys!![]()
Keyboard Not Found! Press any key to continue. . .
>>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