printf zero-pads strings?

Chris Torek chris at mimsy.umd.edu
Wed Oct 25 07:21:31 AEST 1989


In article <1430 at crdos1.crd.ge.COM> davidsen at crdos1.crd.ge.COM
>(Wm E Davidsen Jr) writes:
>I would be delighted if [printf] workds that way ["%05s","x"=>"0000x"],
>having a program which uses it (input strings are digit sequences with
>leading zeros stripped), now I ask you, what does "%-05x" give.

May 13, 1988 draft standard says this about `0' (|xxx| indicates courier
font, for literal C text):

	For |d|, |i|, |o|, |u|, |x|, |X|, |e|, |E|, |f|, |g|, and |G|
	conversions, leading zeros (following any indication of sign
	or base) are used to pad to the field width; no space padding
	is performed.  If the |0| and |-| flags both appear, the |0|
	flag will be ignored.  For |d|, |i|, |o|, |u|, |x|, and |X|
	conversions, if a precision is specified, the |0| flag will
	be ignored.  For other conversions, the behavior is undefined.

We happened to base the %05s zero-fill rule on an earlier draft, which
simply said `zero pad instead of blank pad, but |0| and |-| together
is like |-| alone'.  Hence %-05<any> functions as %-5<any>.
-- 
`They were supposed to be green.'
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.std.c mailing list