Xref: utzoo comp.lang.c:15717 comp.sys.ibm.pc:23596 Path: utzoo!attcan!uunet!husc6!rice!uw-beaver!uw-june!ka From: ka@june.cs.washington.edu (Kenneth Almquist) Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: Re: Microsoft C 5.1 question Summary: "%.2d" and "%02d" are the same Keywords: Printf formats Message-ID: <7026@june.cs.washington.edu> Date: 22 Jan 89 06:51:23 GMT References: <104@rpi.edu> <198@broadway.UUCP> <6951@june.cs.washington.edu> <1587@csuna.UUCP> Organization: U of Washington, Computer Science, Seattle Lines: 24 abcscnge@csuna.UUCP (Scott "The Pseudo-Hacker" Neugroschl) writes: > In article <6951@june.cs.washington.edu> ka@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