comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Converting Type Characters to type string
Date: Mon, 31 Mar 2008 16:21:36 +0200
Date: 2008-03-31T16:21:41+02:00	[thread overview]
Message-ID: <wszmbw04e0i7$.1ogvbnnnxl7eg$.dlg@40tude.net> (raw)
In-Reply-To: e29aa5d8-0de6-4248-b22a-e5dc2094ff00@n58g2000hsf.googlegroups.com

On Mon, 31 Mar 2008 06:50:32 -0700 (PDT), jedivaughn wrote:

> The only problem I'm having is that I don't want to have to add a
> space or another character to the end of my string of numbers. As long
> as I set str : strin (1..999) := (others -> ' '); I can get all the
> characters I want but they have to be followed by something other then
> for a digit. Is there a way to get an input of a length unknown
> without having to take an extra character? 0ne user suggested the
> look_ahead  procedure if that would help solve this how would I use
> that?

Can you tell us what do you want to achieve?

Normally, you would read a source line using Get_Line of Ada.Text_IO. Then
you would process the obtained string. The former is clear. What is about
the latter? What do you want to parse? Integer numbers?

with Ada.Text_IO;            use Ada.Text_IO;
with Strings_Edit.Integers;  use Strings_Edit.Integers;

procedure Numeric_Input is
begin
   loop
      Put_Line ("Enter a number:");
      declare
         Input  : constant String := Get_Line; -- (Ada 2005)
         Number : Integer;
      begin
         exit when Input'Length = 0;
         Number := Value (Input);
         Put_Line ("You typed " & Image (Number));
      exception
         when Data_Error =>
            Put_Line ("Bad input, possibly more than one number");
         when End_Error =>
            Put_Line ("No number found");
         when Constraint_Error =>
            Put_Line ("The number is too large");
      end;
   end loop;
end Numeric_Input;   

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2008-03-31 14:21 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-30 20:04 Converting Type Characters to type string jedivaughn
2008-03-30 20:19 ` Pascal Obry
2008-03-30 21:08   ` jedivaughn
2008-03-30 21:28     ` jimmaureenrogers
2008-03-30 21:38     ` Ludovic Brenta
2008-03-30 21:48   ` Georg Bauhaus
2008-03-30 23:52     ` jedivaughn
2008-03-31  3:04       ` george.priv
2008-03-31  4:00         ` tmoran
2008-03-31  8:54           ` Ludovic Brenta
2008-03-31  9:59             ` Dmitry A. Kazakov
2008-03-31 10:59               ` Jean-Pierre Rosen
2008-03-31 13:50                 ` jedivaughn
2008-03-31 14:11                   ` Ludovic Brenta
2008-03-31 14:21                   ` Dmitry A. Kazakov [this message]
2008-03-31 14:44                     ` jedivaughn
2008-03-31 15:41                       ` Adam Beneschan
2008-03-31 20:26                         ` Maciej Sobczak
2008-03-31 22:06                           ` Georg Bauhaus
2008-03-31 22:33                           ` Adam Beneschan
2008-04-01  1:00                             ` jedivaughn
2008-04-01  5:34                               ` Simon Wright
2008-04-01 11:22                                 ` jedivaughn
2008-04-01 12:00                                   ` jimmaureenrogers
2008-04-01 13:22                                     ` jedivaughn
2008-04-01 17:03                                       ` Adam Beneschan
2008-04-01 21:11                                   ` Simon Wright
2008-04-01 22:22                                     ` jedivaughn
2008-04-03  5:54                                   ` tmoran
2008-04-03 14:38                                     ` Adam Beneschan
2008-04-01 16:58                               ` Adam Beneschan
2008-03-31 15:45                       ` Dmitry A. Kazakov
replies disabled

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