comp.lang.ada
 help / color / mirror / Atom feed
* Did I understand it or not
@ 2014-01-08 20:27 Anh Vo
  2014-01-08 20:47 ` Pascal Obry
  2014-01-08 20:50 ` adambeneschan
  0 siblings, 2 replies; 5+ messages in thread
From: Anh Vo @ 2014-01-08 20:27 UTC (permalink / raw)


with Ada.Text_Io; use Ada;

procedure The_Unexpected is
   package Char_Io is new Ada.Text_Io.Enumeration_Io (Character);
   Health_Choice : Character := 'T';
   use Text_Io;
begin
   Health_Selection: loop
      begin
         Put ("Select Health Status '0', '1' or '2' => ");
         Char_Io.Get (Health_Choice);
         Put_Line (" < character '" & Health_Choice & "' is selected");
         if Health_Choice = '0' or else
            Health_Choice = '1' or else
            Health_Choice = '2' then
              exit;
         else
           Put ("Illegal selection! Choose another character > ");
         end if;
      exception
         when Data_Error =>
            Put_Line ("Use single quote like '0' or '1'");
            Flush;
      end;
   end loop Health_Selection;
end The_Unexpected;
---------------------------------------
GNAT was used on Linux and PC

I thought this piece of code should behave correctly regardless good or bad input from the operator. If a bad data is input, it is rejected and ask for another data input. However, it went to an infinite loop when a bad input is entered. For example, the program is in infinite loop if the operator type 1 instead of '1' when prompted.

I strongly believe that Flush subprogram did not clear the previous input from the terminal. Thus, Char_Io.Get completes without waiting for the input from the operator.

Once it is confirmed, I will compile a bug report. Thank you in advance for your help.

Anh Vo 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Did I understand it or not
  2014-01-08 20:27 Did I understand it or not Anh Vo
@ 2014-01-08 20:47 ` Pascal Obry
  2014-01-08 20:50 ` adambeneschan
  1 sibling, 0 replies; 5+ messages in thread
From: Pascal Obry @ 2014-01-08 20:47 UTC (permalink / raw)


Le 08/01/2014 21:27, Anh Vo a écrit :

> Once it is confirmed, I will compile a bug report. Thank you in
> advance for your help.

Behavior expected, you don't want a Flush (for the output) but Skip_Line
(for the input).

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://v2p.fr.eu.org
  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Did I understand it or not
  2014-01-08 20:27 Did I understand it or not Anh Vo
  2014-01-08 20:47 ` Pascal Obry
@ 2014-01-08 20:50 ` adambeneschan
  2014-01-08 21:02   ` Anh Vo
  1 sibling, 1 reply; 5+ messages in thread
From: adambeneschan @ 2014-01-08 20:50 UTC (permalink / raw)


On Wednesday, January 8, 2014 12:27:54 PM UTC-8, Anh Vo wrote:

> I strongly believe that Flush subprogram did not clear the previous input from the terminal.

Flush, with no parameters, operates on the current *output* file.  In fact, I don't think Flush operates on input at all.  If you give it a file of mode In_File, it raises an exception (A.10.3(20), A.12.1(36)).

                          -- Adam

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Did I understand it or not
  2014-01-08 20:50 ` adambeneschan
@ 2014-01-08 21:02   ` Anh Vo
  2014-01-08 23:36     ` robin.vowels
  0 siblings, 1 reply; 5+ messages in thread
From: Anh Vo @ 2014-01-08 21:02 UTC (permalink / raw)


On Wednesday, January 8, 2014 12:50:23 PM UTC-8, adambe...@gmail.com wrote:
> On Wednesday, January 8, 2014 12:27:54 PM UTC-8, Anh Vo wrote:
> 

> Flush, with no parameters, operates on the current *output* file.  In fact, I don't think Flush operates on input at all.  If you give it a file of mode In_File, it raises an exception (A.10.3(20), A.12.1(36)).
> 

Thank you both Pascal and Adam for your quick reply. This program works correctly now after Flush is replaced by Skip_Line.

A. Vo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Did I understand it or not
  2014-01-08 21:02   ` Anh Vo
@ 2014-01-08 23:36     ` robin.vowels
  0 siblings, 0 replies; 5+ messages in thread
From: robin.vowels @ 2014-01-08 23:36 UTC (permalink / raw)


On Thursday, January 9, 2014 8:02:00 AM UTC+11, Anh Vo wrote:
> On Wednesday, January 8, 2014 12:50:23 PM UTC-8, adambe...@gmail.com wrote: > On Wednesday, January 8, 2014 12:27:54 PM UTC-8, Anh Vo wrote: > > Flush, with no parameters, operates on the current *output* file. In fact, I don't think Flush operates on input at all. If you give it a file of mode In_File, it raises an exception (A.10.3(20), A.12.1(36)). > Thank you both Pascal and Adam for your quick reply. This program works correctly now after Flush is replaced by Skip_Line.

Better still, why not get the program to accept just 0 or 1 without the
apostrophes?

Makes more sense, and is what the operator expects.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-08 23:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-08 20:27 Did I understand it or not Anh Vo
2014-01-08 20:47 ` Pascal Obry
2014-01-08 20:50 ` adambeneschan
2014-01-08 21:02   ` Anh Vo
2014-01-08 23:36     ` robin.vowels

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