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,eee47022b0e39dbb X-Google-Attributes: gid103376,public From: JohnVolan@macconnect.com (John Volan) Subject: Re: Exception problem Date: 1997/03/09 Message-ID: #1/1 X-Deja-AN: 224217591 References: <330A0D25.313@fs2.assist.uci.edu> <3311BFC4.7576@fs2.assist.uci.edu> <5eutjo$rlg@ash.ridgecrest.ca.us> Organization: None Newsgroups: comp.lang.ada Date: 1997-03-09T00:00:00+00:00 List-Id: > I would have written the program almost exactly the way you did. The > only difference is that I would have used "Get_Line(TEXT, LENGTH);" > instead of Get. That would have eliminated the need for the Skip_Line. > > After obtaining the text from the user, I would have used the 'VALUE > attribute to convert TEXT(1 .. LENGTH) to the integer type, if possible. > The 'VALUE attribute will raise an exception if the text string isn't an > integer, so you would have no choice but to use an exception handler. The disadvantage in using 'Value is that it is not very forgiving if the input is not *exactly* an integer literal, i.e., if there is white space before and/or after the integer literal within the input string. An alternative method is to go ahead and read the input line into a string buffer, but then use a Get procedure from an instantiation of Ada.Text_IO.Integer_IO: Get (Text, Length); Get (From => Text (1 .. Length), -- eats any leading whitespace Item => Your_Integer, Last => Next); -- stops at the end of the integer literal, -- before any trailing whitespace (or indeed, -- any trailing anything -- optionally, if you want to do something with the rest of the input line, -- you can do: Next := Next + 1; -- and then do further processing on Text (Next .. Length) > I would have written the program almost exactly the way you did. The > only difference is that I would have used "Get_Line(TEXT, LENGTH);" > instead of Get. That would have eliminated the need for the Skip_Line. > > After obtaining the text from the user, I would have used the 'VALUE > attribute to convert TEXT(1 .. LENGTH) to the integer type, if possible. > The 'VALUE attribute will raise an exception if the text string isn't an > integer, so you would have no choice but to use an exception handler. The disadvantage in using 'Value is that it is not very forgiving if the input is not *exactly* an integer literal, i.e., if there is white space before and/or after the integer literal within the input string. An alternative method is to go ahead and read the input line into a string buffer, but then use a Get procedure from an instantiation of Ada.Text_IO.Integer_IO: Get (Text, Length); Get (From => Text (1 .. Length), -- eats any leading whitespace Item => Your_Integer, Last => Next); -- stops at the end of the integer literal, -- before any trailing whitespace (or indeed, -- any trailing anything -- optionally, if you want to do something with the rest of the input line, -- you can do: Next := Next + 1; -- and then do further processing on Text (Next .. Length) ---------------------------------------------------------------------- Internet.Usenet.Put_Signature (Name => "John G. Volan", Home_Email => "johnvolan@macconnect.com", Slogan => "Ada95: The World's *FIRST* International-Standard OOPL", Disclaimer => "No one ever defined these opinions, so using them" & "is totally erroneous...or is that a bounded error now? :-) "); ----------------------------------------------------------------------