Microsoft C 5.1 question

Andrew Koenig ark at alice.UUCP
Mon Jan 23 03:32:40 AEST 1989


In article <7026 at june.cs.washington.edu>, ka at june.cs.washington.edu (Kenneth Almquist) writes:
> abcscnge at csuna.UUCP (Scott "The Pseudo-Hacker" Neugroschl) writes:
> > In article <6951 at june.cs.washington.edu> ka at june.cs.washington.edu (Kenneth Almquist) writes:
> > ]    printf("%2d:%.2d:%.2d", hour, minute, second);
> > 
> > How about
> >      printf("%2d:%02d:%02d", hour, minute, second);
> 
> These behave identically.  A fair number of years ago, AT&T decided to
> switch from the "%02d" format to the "%.2d" format.

Actually, they behave identically only for positive numbers.

The change came about for several reasons, not all of which
I remember.  One was a desire to be able to print things like
0x00076552, which just didn't fit into the notion of zero-padding.
Another was that `zero-padding' didn't really describe the operation.
After all, if you zero-pad -3 to six characters, you should get
0000-3, right?  Some head-scratching and a lot of discussion
later, we decided that the operation we really wanted was
`guarantee at least a particular number of digits' and that
that should be done as part of conversion, not as part of padding.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list