Microsoft C 5.1 question

Kenneth Almquist ka at june.cs.washington.edu
Sun Jan 22 16:51:23 AEST 1989


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.  A couple of reasons
for this may be:

     1) Conceptual simplicity.  The printf format has a precision field
	for use by the %s and the floating point formats; it makes sense
	to use this same field for integer formats rather than ignoring
	the precision and using some other method of getting zero padding.

     2) Flexibility.  Using the precision to specify the zero padding
	allows the field width to be used for its normal function even
	when zero padding is desired.

The "%02d" format will no doubt continue to work forever.  I've switched
to the new format because I don't expect newcomers to the C world want to
learn all the obsolete features of the language.
				Kenneth Almquist



More information about the Comp.lang.c mailing list