From: tmoran@acm.org
Subject: Re: Newbie question on Ada TExt_IO
Date: Fri, 04 Oct 2002 18:34:47 GMT
Date: 2002-10-04T18:34:47+00:00 [thread overview]
Message-ID: <bbln9.47333$dp1.137194@rwcrnsc52.ops.asp.att.net> (raw)
In-Reply-To: Gwkn9.622$Oa1.417@nwrddc02.gnilink.net
> "last" is the size of the string,
This is true only if Input'first is 1. ie, if you had
Input : String(15 .. 237);
and the user entered 2 characters, Last = 16 and Input(15 .. 16), or
Input(Input'first .. Last), contains the two characters. It's not a good
habit to assume the first subscript is 1 and Last is the length. Often a
String has been passed to you as a parameter to a procedure, and the
caller may have passed just a portion of some bigger string, say
Input : String(1 .. 1024);
...
Input(1 .. 14) := "abcdefghijklmn";
Some_Procedure(Input(15 .. 237));
Some_Procedure will fail if it assumes its input parameter'first = 1.
>How do you evaluate the length of the string using "Input'Last" isn't always
>going to be 256, it was for me?
Input'last is the last legal subscript in Input. Given
Input : String(1 .. 256);
Input'last = 256. Permanently. Regardless of the content of Input.
Last is a variable set by Get_Line that tells the last subscript
Get_Line used to store an input character. If the user entered no
characters then Get_Line sets Last = Input'first-1 (zero in your
example). If he entered four characters "5432", then hit the Enter key,
then the '2' goes into Input(4) and Last = 4.
next prev parent reply other threads:[~2002-10-04 18:34 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 [this message]
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
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