comp.lang.ada
 help / color / mirror / Atom feed
From: agate!spool.mu.edu!howland.reston.ans.net!bogus.sura.net!darwin.sura.net! seas.gwu.edu!mfeldman@ucbvax.Berkeley.EDU  (Michael Feldman)
Subject: Re: simple help with Text_IO
Date: 3 Feb 93 14:14:53 GMT	[thread overview]
Message-ID: <1993Feb3.141453.28853@seas.gwu.edu> (raw)

In article <C1unnH.Lu9@undergrad.math.waterloo.edu> ccalbrec@laplace.uwaterloo.
ca (Cory C. Albrecht) writes:

[stuff deleted]

>With Text_IO; Use Text_IO;
>
>Procedure main is 
>
>instr, tokstr : String(1..255);
                 ^^^^^^^^^^^^^^---------- a 255-character string
>
>Begin
>Loop
>    New_Line;
>    Put("*>> ");
>    Get(instr);                 -- this is where it stalls and won't go furthe
r
     ^^^^^^^^^^^------------------------- which you are trying to read here
>    New_Line;
>    Put("*:: ");
>    Put(instr);
>    Exit When instr="quit";
>End Loop;
>End; --main
>
>
>

Sigh...Ada strings are nothing magic, just arrays of characters. 

Text_IO.Get(...string...) will attempt to read _exactly_ the number of
characters specified (and it skips over CRs!). Your Get will not be 
satisfied until it gets exactly 255 characters. There's nothing "hung"
about your program; it's simply waiting for the rest of the input.

This is an extremely common misunderstanding about strings and Text_IO;
my students bump into it all the time. To solve your problem, use
Get_Line instead. Look it up in your text, or ask your teacher, or
read the LRM section describing how the various Get's work.

(Blatant plug: my freshman-level text explains it pretty well; so
do most newer books.)

Good luck -

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman
co-chair, SIGAda Education Committee

Professor, Dept. of Electrical Engineering and Computer Science
School of Engineering and Applied Science
The George Washington University
Washington, DC 20052 USA
(202) 994-5253 (voice)
(202) 994-5296 (fax)
mfeldman@seas.gwu.edu (Internet)

"Americans want the fruits of patience -- and they want them now."
------------------------------------------------------------------------

             reply	other threads:[~1993-02-03 14:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-02-03 14:14 agate!spool.mu.edu!howland.reston.ans.net!bogus.sura.net!darwin.sura.net! [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-02-04 18:39 simple help with Text_IO agate!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu
1993-02-03 18:21 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!haven.umd.ed
1993-02-03 16:41 Kenneth Anderson
1993-02-03 15:17 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!spool
1993-02-03 14:20 enterpoop.mit.edu!spool.mu.edu!howland.reston.ans.net!bogus.sura.net!jhun
1993-02-03  1:47 agate!spool.mu.edu!sdd.hp.com!elroy.jpl.nasa.gov!usc.edu!cs.utexas.edu!to
replies disabled

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