comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: Newbie question on Ada TExt_IO
Date: Sat, 05 Oct 2002 02:43:48 GMT
Date: 2002-10-05T02:43:48+00:00	[thread overview]
Message-ID: <Elsn9.40374$FO4.9554@sccrnsc03> (raw)
In-Reply-To: Sikn9.1513$Mw4.1034@nwrddc01.gnilink.net

"Justin Birtwell" <jbirtwell@yahoo.com> wrote in message
news:Sikn9.1513$Mw4.1034@nwrddc01.gnilink.net...

> Is_Digit a hack of a procedure that compares the 1 character string to all
> 10 digits characters.  I really have a lot to learn.   What's giving me
the
> hardest time is working within the confines of strict/strong typing.  The
> Ada.Characters.Handling  package already has an Is_Digit function, but
it's
> expecting a character not a single item String array!  How can I convert
> from one into the other?  I have the distinct feelling like I'm
reinventing
> the wheel.  Aren't packages aready made to do alot of this
> converting/validation?  If so where are they?  How can one access them?
> Does the RM list all the packages provided by Ada or are there more to be
> discovered?
>

First, if you happen to be using GNAT on windows, go to the help file "Ada
95 Reference Manual".  Select "Annexes", then "Annex A: Predefined Language
Environment", then "A. Predefined Language Environment".

Or you can go to http://www.adaic.org/standards/95lrm/html/RM-A.html which
has the same information.

This page shows the standard libraries include in Ada 95.  I recommend
perusing these to see what is available.

Second... about your program.  It runs if you change the Input_Data( 1..1)
to Input_Data(1) and add a couple of "with" and "use" clauses to make the
built in library function available... but...  If you enter "42" the program
is happy and recognizes the value entered as "4".  Hmmm... I suspect not
what the user would expect.

Try this one (and please reassure me that this is not a homework assignment
I just completed for you)

with Ada.Text_Io;
 use Ada.Text_Io;
with Ada.Strings;
 use Ada.Strings;
with Ada.Strings.Fixed;
 use Ada.Strings.Fixed;

procedure Test_IO_3 is
  Input: String(1..256);
  Last:Integer;
  result : Integer;
begin
  ReadLoop:
    loop
      Put("Please enter a number between 1 and 6 > ");
      Get_Line(Item=>Input,Last=>Last);
      declare
        Input_Data : String := Trim( Input( 1 .. Last ), Both );
      begin
        if Input_Data'Length = 1 and then
           Input_Data(1) in '1' .. '6' then
           result := Integer'Value( Input_Data( 1 .. 1 ) );
           Exit ReadLoop;
        end if;
        Put_Line("Invalid entry, try again.");
      end;
    end loop ReadLoop;
    Put_Line("Thank you");
exception
  when others=>
    Put_Line("Error, Invalid data.");
end Test_IO_3;



> thanks to one and all,
> Justin
>
>
>
>





  parent reply	other threads:[~2002-10-05  2:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-03 18:20 Newbie question on Ada TExt_IO Justin
2002-10-03 18:50 ` Matthew Heaney
2002-10-03 19:05 ` Jeffrey Carter
2002-10-03 19:35 ` David C. Hoos
2002-10-03 19:35 ` tmoran
2002-10-03 19:43 ` Preben Randhol
2002-10-03 19:55   ` Matthew Heaney
2002-10-03 20:07     ` Preben Randhol
2002-10-04  2:42 ` SteveD
2002-10-04 17:49   ` Justin Birtwell
2002-10-04 18:00     ` David C. Hoos
2002-10-04 18:04       ` Preben Randhol
2002-10-04 18:00     ` Preben Randhol
2002-10-04 18:02       ` Preben Randhol
2002-10-04 18:34     ` tmoran
2002-10-04 17:34 ` Justin Birtwell
2002-10-04 17:58   ` Preben Randhol
2002-10-04 18:13   ` tmoran
2002-10-04 20:07   ` Jeffrey Carter
2002-10-07  8:26     ` Fraser Wilson
2002-10-07 19:44       ` Jeffrey Carter
2002-10-05  2:43   ` SteveD [this message]
2002-10-05  5:25     ` tmoran
  -- strict thread matches above, loose matches on Subject: below --
2002-10-07  6:01 Grein, Christoph
2002-10-07  8:27 Grein, Christoph
2002-10-07 11:48 ` Fraser Wilson
2002-10-07 12:46   ` Robert A Duff
replies disabled

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