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,9adb0110470c093d,start X-Google-Attributes: gid103376,public From: Preben Randhol Subject: Safely converting String to Float ? Date: 1999/11/03 Message-ID: #1/1 X-Deja-AN: 543918335 X-Complaints-To: usenet@itea.ntnu.no X-Trace: kopp.stud.ntnu.no 941631795 8109 129.241.83.82 (3 Nov 1999 12:23:15 GMT) Organization: ProgramVareVerkstedet NNTP-Posting-Date: 3 Nov 1999 12:23:15 GMT Newsgroups: comp.lang.ada Date: 1999-11-03T12:23:15+00:00 List-Id: 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