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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,49f7dd1bad1910ff X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-15 18:19:48 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Problems with Ada.Text_IO and strings. References: <8336eb21.0310131423.7410e1ec@posting.google.com> <1106548.PnMF1M2W6X@linux1.krischik.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 16 Oct 2003 01:19:48 GMT NNTP-Posting-Host: 63.184.32.68 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1066267188 63.184.32.68 (Wed, 15 Oct 2003 18:19:48 PDT) NNTP-Posting-Date: Wed, 15 Oct 2003 18:19:48 PDT Xref: archiver1.google.com comp.lang.ada:933 Date: 2003-10-16T01:19:48+00:00 List-Id: Ludovic Brenta wrote: > I'm not going to post working code and do your homework for you, but > here are hints you may find useful. > > Hint 1: > > declare > S : String (1 .. 20); > Last : Natural; > begin > Ada.Text_IO.Get_Line (S, Last); -- User's input is S (S'First .. Last) > end; > > Hint 2: if Last = S'Last, then you will want to call > Ada.Text_IO.Get_Line again to read the rest of the input, and > concatenate this to S. > > Hint 3: recursive calls are your friends. I don't think this is what the OP is looking for (a Get_Line function). One way to deal with this is to read into a really long String using Get_Line, then use Ada.Strings.Fixed.Move to transfer the value to the Name variable. It's unlikely that a user will type in 100 characters for a name; 1000 practically guarantees that Get_Line will get the entire line. Another is to write Get_Line yourself, not because you need to, but because it helps you understand what Get_Line is doing: procedure Get_Line (Item : out String; Last : out Natural) is begin Last := Item'First - 1; Read : for I in Item'range loop if End_Of_Line then Skip_Line; return; end if; Get (Item (I) ); Last := I; end loop Read; end Get_Line; The important point is that Skip_Line is only called inside the loop. The loop exits when Item is completely filled; Skip_Line is not called. If the loop exits, Last = Item'Last. Thus, if on return from Get_Line, Last = Item'Last, then there is at least an unprocessed line terminator in the buffer, possibly preceded by some unprocessed characters. You can get rid of these by calling Skip_Line yourself. You can also write a procedure to deal with all of this: procedure Get_Whole_Line (Item : out String; Last : out Natural) is begin Get_Line (Item, Last); if Last = Item'Last then Skip_Line; end if; end Get_Whole_Line; -- Jeff Carter "Go and boil your bottoms." Monty Python & the Holy Grail 01