printf zero-pads strings?

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Thu Oct 26 04:22:47 AEST 1989


In article <20371 at mimsy.umd.edu>, chris at mimsy.umd.edu (Chris Torek) writes:
	if a precision is specified, the |0| flag will be ignored.
	(quoted from the standard)

  This certainly doesn't grab me as being 'least astonishment.' I
interpret this to mean that if I say %010.2f the |0| is ignored. Yes? My
copy of the standard is on loan, I can't check that you quoted it
correctly, but the context (from which I extracted it) doesn't seem to
refer to this.

  Could someone explain why this works this way? I certainly find it
easier to explain when leading zero means pad with zeros. Period. What
was the thinking that specifying precision in some way made zero fill
undesirable?

  Adding a leading zero is not the type of thing one does by accident.
It would be nice if it had been defined to either cause leading zeros or
be a runtime error. Ignoring a user request for action is a good way to
create hard to find errors (my opinion).
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon



More information about the Comp.std.c mailing list