A question...

Dave Turner dmt at PacBell.COM
Sun Aug 20 06:33:03 AEST 1989


In article <322 at cubmol.BIO.COLUMBIA.EDU> ping at cubmol.UUCP (Shiping Zhang) writes:
.In article <1025 at virtech.UUCP> cpcahil at 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



More information about the Comp.lang.c mailing list