From: Preben Randhol <randhol@pvv.org>
Subject: Safely converting String to Float ?
Date: 1999/11/03
Date: 1999-11-03T12:23:15+00:00 [thread overview]
Message-ID: <m3n1svbw6t.fsf@kiuk0156.chembio.ntnu.no> (raw)
How do one safely (no program crash) convert a String to a Float?
This little code will dump core:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings; use Ada.Strings;
procedure StrToFloat is
package My_Float_IO is new
Ada.Text_IO.Float_IO(Float);
use My_Float_IO;
Tekst : String(1..5) := "12.34";
Tekst2 : String(1..6) := "d12.34";
Tall : Float;
Size : Integer;
Tall_F : Float;
Size_F : Integer;
begin
Get(Tekst,Tall,Size);
Get(Tekst2,Tall_F,Size_F);
end;
it will dump core because of the d in Tekst2. Does somebody know how
to do this conversion without core dumping? I'm not trying to convert
the d12.34, but I would like the program to deal with the failure of
conversion in a kinder manner.
I'm using Gnat 3.12p on a Linux 2.2.x System (Redhat 6.0). And I'm an
Ada newbie.
Any hints much appreciated...
--
Preben Randhol Affliction is enamoured of thy parts,
[randhol@pvv.org] And thou art wedded to calamity.
[http://www.pvv.org/~randhol/] -- W. Shakespeare
next reply other threads:[~1999-11-03 0:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-11-03 0:00 Preben Randhol [this message]
1999-11-03 0:00 ` Safely converting String to Float ? Matthew Heaney
1999-11-03 0:00 ` Preben Randhol
1999-11-03 0:00 ` Lutz Donnerhacke
1999-11-03 0:00 ` Preben Randhol
1999-11-08 0:00 ` Robert A Duff
1999-11-09 0:00 ` Preben Randhol
1999-11-03 0:00 ` Gautier
1999-11-03 0:00 ` Robert Dewar
1999-11-03 0:00 ` Robert Dewar
1999-11-03 0:00 ` Preben Randhol
1999-11-03 0:00 ` Samuel Tardieu
1999-11-04 0:00 ` [SOLVED] " Preben Randhol
1999-11-04 0:00 ` Jürgen Pfeifer
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox