comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Interger_io get and Text_io.Get_line
Date: Fri, 17 Oct 2003 01:01:57 GMT
Date: 2003-10-17T01:01:57+00:00	[thread overview]
Message-ID: <9cHjb.3520$s93.924@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: <w6Djb.4918$Z_2.407289@news20.bellglobal.com>

CheGueVerra wrote:

> Okay, after playing with it some more, I found that if I do this
> 
>  Put_line("Enter a number");
>  Entiers.get(Number, 2);
>  Skip_line;
>  Put_line("Enter a string");
>  Get_Line(TstStr, Last);
>  Put_line(TstStr(TstStr'First..Last));

Good. You've fixed the Put_Line, which before was displaying the entire 
string.

> 
> 
> then the program runs as I expect it to do, the thing is I don't understand
> why I need a Skip_line for it to work, So if anyone can shed some light on
> that I would appriciate it

You had 2 lines: 1 with a number, and one with a string. Integer_IO.Get 
gets the number. It does not skip the line terminator. The Skip_Line 
does that. Without the Skip_Line, your Get_Line gets the null string 
left on the number's line and skips that line terminator.

Things get even worse if you make an error entering the number. Try 
entering "X" for the number and see what you get. For this reason, 
getting numeric input is usually best done be getting a string, then 
using 'Image or Get from the numeric IO packages in Text_IO to extract 
the number. This should be done inside a block to handle exceptions from 
illegal input, and that should be inside a block to give the user 
multiple tries to get it right.

-- 
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail
10




  parent reply	other threads:[~2003-10-17  1:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-16 20:12 Interger_io get and Text_io.Get_line CheGueVerra
2003-10-16 20:22 ` CheGueVerra
2003-10-16 23:31   ` Robert I. Eachus
2003-10-17  1:01   ` Jeffrey Carter [this message]
2003-10-17  1:15     ` CheGueVerra
2003-10-17  5:08     ` Anders Wirzenius
2003-10-17  5:59       ` Anders Wirzenius
replies disabled

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