comp.lang.ada
 help / color / mirror / Atom feed
* Interger_io get and Text_io.Get_line
@ 2003-10-16 20:12 CheGueVerra
  2003-10-16 20:22 ` CheGueVerra
  0 siblings, 1 reply; 7+ messages in thread
From: CheGueVerra @ 2003-10-16 20:12 UTC (permalink / raw)


I figured out who to play with the strings and get the desired length out of
my strings, but now I have an other trouble.

When I try to Get an Integer and then Get_line a String, the Integer works
great, but it seems to jumps over the Get_line.

[Code Snippet]
with Text_io;
use Text_io;

Procedure TestString is
 subType MyString is string(1..10);

 package Entiers is new Text_io.Integer_io (Num => Integer);

   Last   : Natural := 0;
   TstStr : MyString;
 Number : integer;
begin
 Put_line("Test of string 10");
 Put_line("Enter a number");
 Entiers.get(Number);
 New_line;
 Put_line("Enter a string");
 ====
 it seems to skip this line and go directly to the Put_line
 Get_Line(TstStr, Last);
 =====
 Put_line(TstStr(TstStr'First..TstStr'Last));
 Entiers.Put(Number);
end TestString;


So, I figure that I'm doing something wrong  AGAIN, and been trying to
figure what, but after a couple of hours trying I'm getting really mad with
myself and ada, I feel like I can't even write code anymore, because this is
really basic stuff and I can't seem to figure it out

CheGueVerra





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

* Re: Interger_io get and Text_io.Get_line
  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
  0 siblings, 2 replies; 7+ messages in thread
From: CheGueVerra @ 2003-10-16 20:22 UTC (permalink / raw)


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));


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

TIA

CheGueVerra





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

* Re: Interger_io get and Text_io.Get_line
  2003-10-16 20:22 ` CheGueVerra
@ 2003-10-16 23:31   ` Robert I. Eachus
  2003-10-17  1:01   ` Jeffrey Carter
  1 sibling, 0 replies; 7+ messages in thread
From: Robert I. Eachus @ 2003-10-16 23:31 UTC (permalink / raw)


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));
> 
> 
> 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

The Get for Number reads a number, the Skip_Line reads the End_of_Line 
following it.  I won't go into all the gory details of how to set reads 
from the console to character at a time from line at a time, etc.

Notice that without the fix, entering the number followed on the same 
line by the string would work.


-- 
                                                     Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




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

* Re: Interger_io get and Text_io.Get_line
  2003-10-16 20:22 ` CheGueVerra
  2003-10-16 23:31   ` Robert I. Eachus
@ 2003-10-17  1:01   ` Jeffrey Carter
  2003-10-17  1:15     ` CheGueVerra
  2003-10-17  5:08     ` Anders Wirzenius
  1 sibling, 2 replies; 7+ messages in thread
From: Jeffrey Carter @ 2003-10-17  1:01 UTC (permalink / raw)


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




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

* Re: Interger_io get and Text_io.Get_line
  2003-10-17  1:01   ` Jeffrey Carter
@ 2003-10-17  1:15     ` CheGueVerra
  2003-10-17  5:08     ` Anders Wirzenius
  1 sibling, 0 replies; 7+ messages in thread
From: CheGueVerra @ 2003-10-17  1:15 UTC (permalink / raw)


> 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.

He he he, I think you saw me coming, for now I'm concetrating on getting
most of the things working with valid data, but data control posts will be
coming for sure...

CheGueVerra





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

* Re: Interger_io get and Text_io.Get_line
  2003-10-17  1:01   ` Jeffrey Carter
  2003-10-17  1:15     ` CheGueVerra
@ 2003-10-17  5:08     ` Anders Wirzenius
  2003-10-17  5:59       ` Anders Wirzenius
  1 sibling, 1 reply; 7+ messages in thread
From: Anders Wirzenius @ 2003-10-17  5:08 UTC (permalink / raw)



"Jeffrey Carter" <spam@spam.com> wrote in message
news:9cHjb.3520$s93.924@newsread3.news.pas.earthlink.net...
> CheGueVerra wrote:
>
> >  subType MyString is string(10..20);
> >  TstStr : MyString;
> > ...
> >  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.

Note that the code now works with also

subtype MyString is string(47..57);  -- btw, 11 characters, not 10
...
Get_Line(TstStr, Last);
Put_Line(TstStr(TstStr'First..Last);

2cts

Anders




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

* Re: Interger_io get and Text_io.Get_line
  2003-10-17  5:08     ` Anders Wirzenius
@ 2003-10-17  5:59       ` Anders Wirzenius
  0 siblings, 0 replies; 7+ messages in thread
From: Anders Wirzenius @ 2003-10-17  5:59 UTC (permalink / raw)


"Anders Wirzenius" <anders.wirzenius@pp.qnet.fi> wrote in message
news:lPKjb.15$uW6.1@read3.inet.fi...
 > CheGueVerra wrote:
> >
> > >  subType MyString is string(10..20);
> > >  TstStr : MyString;

> Note that the code now works with also
>
> subtype MyString is string(47..57);  -- btw, 11 characters, not 10
> ...

Sorry, cla

I had still in mind the OP line:
subType MyString is string(1..10);

Anders





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

end of thread, other threads:[~2003-10-17  5:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2003-10-17  1:15     ` CheGueVerra
2003-10-17  5:08     ` Anders Wirzenius
2003-10-17  5:59       ` Anders Wirzenius

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