Xref: utzoo comp.lang.c:15562 comp.sys.ibm.pc:23312 Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!cornell!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 Keywords: Printf formats Message-ID: <6951@june.cs.washington.edu> Date: 16 Jan 89 12:46:45 GMT References: <104@rpi.edu> <198@broadway.UUCP> Organization: U of Washington, Computer Science, Seattle Lines: 19 ] if(minute < 10) ] sprintf(min_str, "0%d", minute); ] else ] sprintf(min_str, "%d", minute); ] ] if(second < 10) ] sprintf(sec_str, "0%d", second); ] else ] sprintf(sec_str, "%d", second); ] ] printf("%2d:%s:%s", hour, min_str, sec_str); This can be shortened to printf("%2d:%.2d:%.2d", hour, minute, second); A "." introduces a precision, which specifies the minimum number of digits to print. Kenneth Almquist