From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,22b2c05a8088bbb2,start X-Google-Attributes: gid103376,public From: baldwin@netcom.com (J.D. Baldwin) Subject: Leading zeros with Int_IO.Put()? Or another package? Date: 1996/11/05 Message-ID: #1/1 X-Deja-AN: 194661007 sender: baldwin@netcom7.netcom.com organization: Revealed on a need-to-know basis. newsgroups: comp.lang.ada Date: 1996-11-05T00:00:00+00:00 List-Id: A "how-to" question from an Ada dabbler: I just got a copy of GNAT and 'make'-ed the examples. The first one I ran, cal.exe, gave me the following date and time: 11/5/1996 10:4:3 . . . when what one *wants* of course is: 11/05/1996 11:04:03 (Leading zero optional--but, by me, preferred--for the date; omitting it is of course inexcusable for the minutes and seconds fields in the time.) In C, building a formatted string takes care of such silliness. (Spare me a list of C's other, more-than-offsetting, shortcomings, please.) I seem to recall from the mists of the distant past that Pascal provided a means of accomplishing this, too. I searched the c.l.a archives at DejaNews, I web-searched for Int_IO, I scanned the FAQ and I read the appropriate sections of RM95 (A.10.8 and adjacent). I found nothing about leading zeros except as pertains to exponent portions of floating point numbers. (Actually, I found one snippet of example code that implemented the same kludge I did.) So I added relevant lines of code to CAL.ADB: if (MINUTE <= 9) then Int_IO.Put(0, 0); end if; Int_IO.Put(MINUTE,0); . . . and so forth, for each relevant value. My question: is there a better way to pad out integers with leading zeros? What if I wanted to pad to a width of three or four or sixteen, all with zeros? Is there a standard way to achieve this in Ada? -- From the catapult of J.D. Baldwin |+| "If anyone disagrees with anything I _,_ Finger baldwin@netcom.com |+| say, I am quite prepared not only to _|70|___:::)=}- for PGP public |+| retract it, but also to deny under \ / key information. |+| oath that I ever said it." --T. Lehrer ***~~~~-----------------------------------------------------------------------