comp.lang.ada
 help / color / mirror / Atom feed
From: e81bnick@kommsrv.rz.unibw-muenchen.de (Nicolay Belofastow)
Subject: Re: Strange problem in GNAT 3.04 Win 95
Date: 1996/10/24
Date: 1996-10-24T00:00:00+00:00	[thread overview]
Message-ID: <54ocn1$604@infosrv.rz.unibw-muenchen.de> (raw)
In-Reply-To: 32707cd0.8077937@news.demon.co.uk


Hello!

smoore@chowgar.demon.co.uk (Simon Moore) writes:

>If anybody has got the time could they please take a look at the
>listing below. The code seems syntactically and semantically correct
>but doesn't perform as it should.

>When 2 is selected you don't get the chance to input a character
>although option 1 works fine.

>But, if you un-coment the get(c) before the case statement the program
>works fine. It doesn't bother with that get(c) but the one inside the
>case statement does.

>Any ideas?


>-- ** Program listing ** --

>with gnat.io; use gnat.io;

>procedure t1 is

>	choice: INTEGER;
>	n: NATURAL;
>	c: CHARACTER;
>	quitflag: BOOLEAN:= FALSE;

>BEGIN

>	WHILE quitflag= FALSE LOOP

>		NEW_LINE;
>		PUT_LINE("Select an option");
>		PUT_LINE("****************");
>		PUT_LINE("1 - Get a natural");
>		PUT_LINE("2 - Get a character");
>		PUT_LINE("3 - Nothing");
>		PUT_LINE("4 - Nothing");
>		NEW_LINE;
>		PUT_LINE("0 - Exit");
>  
>		GET(choice);

>		-- ** GET(c);	-- THIS IS THE IMPORTANT LINE

>		CASE choice IS

>			WHEN 1 =>
>				PUT_LINE("Selection 1");
>				GET(n);
>				PUT(n);
>				PUT_LINE(" was entered");
>				PUT_LINE("~~~~~~~");
>      
>			WHEN 2 =>
>				PUT_LINE("Selection 2");
>				GET(c);
>				PUT(c);
>				PUT_LINE(" was entered");
>				PUT_LINE("~~~~~~~");

>			WHEN 3 =>
>				PUT_LINE("Selection 3");
>				PUT_LINE("~~~~~~~");
>      
>			 WHEN 4 =>
>				PUT_LINE("Selection 4");
>				PUT_LINE("~~~~~~~");

>			WHEN 0 =>
>				quitflag:= TRUE;
>    
>			WHEN others =>
>				PUT("Invalid entry");

>		END CASE;

>	END LOOP;

>END t1;

I am novice in Ada, but from my C experience I know, that sometimes
after usage of scanf function to make a formatted input (e.g. integer
value, as you do) some extra character remains in the keyboard
 and following getchar (getc in Ada) eats it and so makes no expected
 input. 

 May be GNAT compiler uses inside of  the I/O package
 this C functinality. I see only  one way to overcome 
 the problem -- the same, you did -- 
 use extra getc call after the integet input.

 Best regards, Nick.
--
-------------------------------------------------
Nickolay Belofastow
University of the Federal Armed Forces, Munich
e81bnick@rz.unibw-muenchen.de




  reply	other threads:[~1996-10-24  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-24  0:00 Strange problem in GNAT 3.04 Win 95 Simon Moore
1996-10-24  0:00 ` Nicolay Belofastow [this message]
1996-10-25  0:00   ` Simon Moore
1996-10-25  0:00 ` Pascal Obry
1996-10-26  0:00 ` Tom Griest
1996-10-31  0:00 ` John English
replies disabled

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