Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!usc!apple!ames!pacbell!ptsfa!dmt From: dmt@PacBell.COM (Dave Turner) Newsgroups: comp.lang.c Subject: Re: A question... Message-ID: <4932@ptsfa.PacBell.COM> Date: 19 Aug 89 20:33:03 GMT References: <1586@sunset.MATH.UCLA.EDU> <1025@virtech.UUCP> <322@cubmol.BIO.COLUMBIA.EDU> Reply-To: dmt@PacBell.COM (Dave Turner) Distribution: na Organization: Pacific * Bell, San Ramon, CA Lines: 21 In article <322@cubmol.BIO.COLUMBIA.EDU> ping@cubmol.UUCP (Shiping Zhang) writes: .In article <1025@virtech.UUCP> cpcahil@virtech.UUCP (Conor P. Cahill) writes: .> 2. Change the strncpy()s and strcats()s to a single sprintf as .> follows: .> sprintf(str_time, "%2s:%2s:%2s" local_str, local_str+2, .> local_str+4); .The second solution is wrong. %2s does not limit the number of .characters to 2. It only specifies the MINIMUM feild. If the length .of local_str is 6, then the length of str_time will be 12 after .sprintf(). But %2.2s and %.2s will both work the way the original poster wants. Try: sprintf(str_time, "%2.2s:%2.2s:%2.2s", local_str, local_str+2, local_str+4); -- Dave Turner 415/542-1299 {att,bellcore,sun,ames,decwrl}!pacbell!dmt