Path: utzoo!attcan!uunet!ginosko!rex!ames!ucsd!rutgers!columbia!cubmol!ping From: ping@cubmol.BIO.COLUMBIA.EDU (Shiping Zhang) Newsgroups: comp.lang.c Subject: Re: A question... Message-ID: <322@cubmol.BIO.COLUMBIA.EDU> Date: 17 Aug 89 15:44:12 GMT References: <1586@sunset.MATH.UCLA.EDU> <1025@virtech.UUCP> Reply-To: ping@cubmol.UUCP (Shiping Zhang) Distribution: na Organization: Dept. of Biology, Columbia Univ., New York, NY Lines: 16 In article <1025@virtech.UUCP> cpcahil@virtech.UUCP (Conor P. Cahill) writes: > >Solution: > 1. Place a null in str_time[2] after the strncpy(). > 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(). -ping