From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 25 Mar 92 06:00:02 GMT From: news.u.washington.edu!milton.u.washington.edu!mfeldman@beaver.cs.washingt on.edu (Michael Feldman) Subject: Re: Wanted: string conversion in Ada Message-ID: <1992Mar25.060002.3027@u.washington.edu> List-Id: In article <1992Mar23.175436.23472@src.honeywell.com> englehar@src.honeywell.co m (Matt Englehart) writes: >Does anyone have a string conversion package that I could use? I want >something like C's sprintf. (to do atoi, atof ...) > There are 2 well-defined and standard approaches to this: 1. Use the 'Image and 'Value attributes. These are defined for integer and enumeration types, but, alas, not for Float types. If X is an integer variable, then Integer'Image(X) is the equivalent of itoa. If S is a string havng the form of an integer literal, then Integer'Value(S) is the equivalent of atoi. (If S is not a valid numeric literal, Constraint_Error is raised). 2. Text_IO provides _direct_ equivalents to sscanf and sprintf. If you look at the spec for Text_IO (in the LRM or any decent text), you'll discover that ALL the get's and put's have versions that read from and write to strings instead of files. The main difference between these and sscanf/sprintf is that the Ada ones only do a single value at a time, bevcause they are just ordinary Ada procedures. There's no "magic" like the C ones have, which allows sprintf to take an arbitrary number of arguments. Good luck. Mike Feldman ------------------------------------------------------------------------------- Michael B. Feldman co-chair, SIGAda Education Committee Visiting Professor 1991-92 Professor Dept. of Comp. Sci. and Engrg. Dept. of Elect. Engrg. and Comp. Sci. University of Washington FR-35 The George Washington University Seattle, WA 98105 Washington, DC 20052 mfeldman@cs.washington.edu mfeldman@seas.gwu.edu (206) 632-3794 (voice) (202) 994-5253 (voice) (206) 543-2969 (fax) (202) 994-5296 (fax) -------------------------------------------------------------------------------