comp.lang.ada
 help / color / mirror / Atom feed
From: news.u.washington.edu!milton.u.washington.edu!mfeldman@beaver.cs.washingt on.edu  (Michael Feldman)
Subject: Re: Wanted: string conversion in Ada
Date: 25 Mar 92 06:00:02 GMT	[thread overview]
Message-ID: <1992Mar25.060002.3027@u.washington.edu> (raw)

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)
-------------------------------------------------------------------------------
   

             reply	other threads:[~1992-03-25  6:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-03-25  6:00 news.u.washington.edu!milton.u.washington.edu!mfeldman [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-03-23 19:27 Wanted: string conversion in Ada cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!src.honeywell.com!sa
1992-03-23 17:54 dog.ee.lbl.gov!network.ucsd.edu!usc!wupost!uwm.edu!src.honeywell.com!engl
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox