Path: utzoo!attcan!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ginosko!aplcen!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: printf zero-pads strings? Message-ID: <20371@mimsy.umd.edu> Date: 24 Oct 89 21:21:31 GMT References: <7279@sdcsvax.UCSD.Edu> <20327@mimsy.umd.edu> <1430@crdos1.crd.ge.COM> Distribution: na Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 24 In article <1430@crdos1.crd.ge.COM> davidsen@crdos1.crd.ge.COM >(Wm E Davidsen Jr) writes: >I would be delighted if [printf] workds that way ["%05s","x"=>"0000x"], >having a program which uses it (input strings are digit sequences with >leading zeros stripped), now I ask you, what does "%-05x" give. May 13, 1988 draft standard says this about `0' (|xxx| indicates courier font, for literal C text): For |d|, |i|, |o|, |u|, |x|, |X|, |e|, |E|, |f|, |g|, and |G| conversions, leading zeros (following any indication of sign or base) are used to pad to the field width; no space padding is performed. If the |0| and |-| flags both appear, the |0| flag will be ignored. For |d|, |i|, |o|, |u|, |x|, and |X| conversions, if a precision is specified, the |0| flag will be ignored. For other conversions, the behavior is undefined. We happened to base the %05s zero-fill rule on an earlier draft, which simply said `zero pad instead of blank pad, but |0| and |-| together is like |-| alone'. Hence %-05 functions as %-5. -- `They were supposed to be green.' In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris