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,5d47c120235ba244 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Text_IO.Get_Line Date: 1997/05/18 Message-ID: #1/1 X-Deja-AN: 242282084 References: <19970517194301.PAA19410@ladder02.news.aol.com> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-05-18T00:00:00+00:00 List-Id: In article <19970517194301.PAA19410@ladder02.news.aol.com>, rehixon@aol.com (RE Hixon) wrote: >This may have a simple fix, but it has me perplexed. I have used several >different Ada compilers (Ada 83 and 95) on different types of Intel based >systems and keep getting the same results. When I use Get_Line and enter >more characters than the specified string will hold; the remaining >characters stay in the input buffer waiting for the next Get. This causes >an exception to occur. My fix is to execute a Skip_Line after each >Get_Line, but this seems inefficient. Any ideas, or reasons why I am >getting these results? This is expected behavior. Get_Line only returns as many characters as can be contained in the buffer you've declared to hold the input string. The simplest way of detected whether you've read all of the input characters is to compare Last (one one the return values of Get_Line) to Buffer'Last: if Last < Buffer'Last, this means you've read the entire string. If you want to save the entire input string (not throw the end of it away with Skip_Line), then copy each segment you read using Get_Line into an Unbounded_String: declare The_Line : Ada.Strings.Unbounded.Unbounded_String; The_Line_Segment : String (1 .. 80); Last : Natural; begin Get_Entire_Line: loop Text_IO.Get_Line (The_Line_Segment, Last); Append (The_Line, New_Item => The_Line_Segment (1 .. Last)); exit Get_Entire_Line when Last < The_Line_Segment'Last; end loop Get_Entire_Line; end; You could also use a recursive solution: declare function Get_Line return String is The_Line : String (1 .. 80); Last : Natural; begin Text_IO.Get_Line (The_Line, Last); if Last < The_Line'Last then return The_Line (1 .. Last); else return The_Line & Get_Line; end if; end Get_Line; The_Line : constant String := Get_Line; begin ... Hope that helps, Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271