comp.lang.ada
 help / color / mirror / Atom feed
* Wanted: string conversion in Ada
@ 1992-03-23 17:54 dog.ee.lbl.gov!network.ucsd.edu!usc!wupost!uwm.edu!src.honeywell.com!engl
  0 siblings, 0 replies; 3+ messages in thread
From: dog.ee.lbl.gov!network.ucsd.edu!usc!wupost!uwm.edu!src.honeywell.com!engl @ 1992-03-23 17:54 UTC (permalink / raw)


Does anyone have a string conversion package that I could use?  I want
something like C's sprintf. (to do atoi, atof ...)

Thanks, Matt Englehart

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Wanted: string conversion in Ada
@ 1992-03-23 19:27 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!src.honeywell.com!sa
  0 siblings, 0 replies; 3+ messages in thread
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!src.honeywell.com!sa @ 1992-03-23 19:27 UTC (permalink / 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 ...)
>

If you have access to Text_IO in your system, it includes procedures to
to convert strings to integer, integer to string, string to float, etc.  If
you instantiate integer_io (contained in Text_IO), then

  Your_Integer_IO.Get(  -- converts from string to integer
  Your_Integer_IO.Put(  -- converts from integer to string

ditto for float_IO and fixed_IO.  See the specification of Text_IO in
you LRM for details.

Mark Dunbar

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Wanted: string conversion in Ada
@ 1992-03-25  6:00 news.u.washington.edu!milton.u.washington.edu!mfeldman
  0 siblings, 0 replies; 3+ messages in thread
From: news.u.washington.edu!milton.u.washington.edu!mfeldman @ 1992-03-25  6:00 UTC (permalink / 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)
-------------------------------------------------------------------------------
   

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1992-03-25  6:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
  -- strict thread matches above, loose matches on Subject: below --
1992-03-25  6:00 news.u.washington.edu!milton.u.washington.edu!mfeldman
1992-03-23 17:54 dog.ee.lbl.gov!network.ucsd.edu!usc!wupost!uwm.edu!src.honeywell.com!engl

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