comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: Problem with Get_Line
Date: Fri, 27 Sep 2002 19:51:15 GMT
Date: 2002-09-27T19:51:15+00:00	[thread overview]
Message-ID: <TE2l9.545$CN2.350@nwrddc01.gnilink.net> (raw)
In-Reply-To: mailman.1033014963.1915.comp.lang.ada@ada.eu.org

The problem with this program is the way it manages the input stream. When
an integer is read from the input stream, as is done with the call

    Get(Opc);

the I/O routine skips leading white space (if any), then reads in characters
that can be used to represent an integer. No characters past the integer are
removed from the input stream.

Now assume that the user presses the '1' key followed by the enter key. Then
the input stream will have

    1<EOL>

where <EOL> is the end-of-line marker. After the "Get(Opc)" call, Opc is set
to 1 and the input stream will contain

    <EOL>

If you call Get_Line at this point, then it will correctly see that there is
an empty line in the input stream, and return an indcation of that fact.
That is precisely what is happening in your program.

This is not really an Ada issue, mistakes like this are also made in C.
After the "Get(Opc)" call, add a call to the Ada.Text_Io procedure Skip_Line
to discard the characters up to and including the next end-of-line marker.






  reply	other threads:[~2002-09-27 19:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-26  5:35 Problem with Get_Line Mauricio Tellez
2002-09-27 19:51 ` Frank J. Lhota [this message]
2002-10-02 15:22   ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
2002-09-26  5:34 Grein, Christoph
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox