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.

Printable View

- 12-14-2008lolguyNoob printf question
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. - 12-14-2008itCbitC
Lookup the printf() manpage; the 9 in %.9d is the precision which dictates the minimum number of digits that will appear in the output.

- 12-14-2008matsp
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 giveCode:`0123`

If the number is more than 4 digits, it will print the entire number using as many digits as it needs.

--

Mats - 12-14-2008lolguy
thanks alot dude i understand it now