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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cbb87dd49168c396 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-31 13:56:47 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed-west.nntpserver.com!hub1.meganetnews.com!nntpserver.com!telocity-west!TELOCITY!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Get_Line Date: Thu, 31 Oct 2002 16:55:24 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:30271 Date: 2002-10-31T16:55:24-05:00 List-Id: "Justin Birtwell" wrote in message news:B7Cv9.32984$iV1.11543@nwrddc02.gnilink.net... > > I'm having some strange behavior with Get_Line. In a procedure called > GetData I call Get_Line to receive input from the command line. The first > time this function is called it behaves fine prompting the user for input. > The second time it runs the execution passes through Get_Line and no prompt > appears on the command line. Upon doing a little research in the Ref Man. > I found a statement that talks about if Get_Line finds a line terminator it > automatically returns. But how can this be? You might want to read my get_line article at adapower: http://www.adapower.com/lang/get_line.html Get_Line indicates that the entire line has been consumed by returning fewer characters in the read request than are available in the buffer. For example: declare Max_Length : constant := 80; Line : String (1 .. Max_Length + 1); Last : Natural; begin Get_Line (Line, Last); if Last < Line'Last then --entire line was consumed else --entire line was NOT consumed end if; end; There are two approaches for handling the case that not all input was consumed: 1) decide by fiat that the input was too long, and demand that the user enter something shorter: Line : String (1 .. Max_Length + 1); Last : Natural; Read_Response: loop Put ("ready: "); Get_Line (...); exit when Last < Line'Last; Skip_Line; Put_Line ("input too long; try again"); end loop Read_Response; 2) simply copy what you read into an unbounded string, and then consume the rest of the line as necessary: Input : Unbounded_String; Put ("ready: "); Read_Response: loop declare ... begin Get_Line (...); Append (Input, Line (Line'First .. Last)); exit when Last < Line'Last; end; end Read_Response; These two techniques will satisfy the majority of most programmers' needs.