Hey i new to C i wanted to ask a noob printf question
why sometimes in like for printing out character we do %.1d what that 1 before integer for ? i Tried looking it over what does it mean and i added like %.9d it added a couple of zeroes.
thanks.
Hey i new to C i wanted to ask a noob printf question
why sometimes in like for printing out character we do %.1d what that 1 before integer for ? i Tried looking it over what does it mean and i added like %.9d it added a couple of zeroes.
thanks.
Lookup the printf() manpage; the 9 in %.9d is the precision which dictates the minimum number of digits that will appear in the output.
If you use "%4d" then it means "print the number using 4 positions". "%5.4d" means "use 5 positions, and use digits for 4 of those", fill with zeros to make up missing digits, and spaces to make up the rest of the space.
"%5.4d" used on the number 123 will giveas the output.Code:0123
If the number is more than 4 digits, it will print the entire number using as many digits as it needs.
--
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.
thanks alot dude i understand it now