comp.lang.ada
 help / color / mirror / Atom feed
From: agate!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu !destroyer!cs.ubc.ca!van-bc!mdavcr!russell@ucbvax.Berkeley.EDU  (Norman Russell
Subject: Re: simple help with Text_IO
Date: 4 Feb 93 18:39:30 GMT	[thread overview]
Message-ID: <4005@mdavcr.mda.ca> (raw)

In article <C1unnH.Lu9@undergrad.math.waterloo.edu> ccalbrec@laplace.uwaterloo.
ca (Cory C. Albrecht) writes:
>Could somebody tell me (email please) why this programme,
>which compiles properly, seemingly stalls at the
>line indicated? i.e. I type in a line followed by <cr>,
>but nothing happens. What should happen is that this:
>
>*:: <the line that was typed>
>
>should be printed to the console, but isn't. And nothing
>happens. The input prompt:
>
>*>>
>
>is printed, then I can type something, but after <cr>
>nothing happens. :(
>
>
>With Text_IO; Use Text_IO;
>
>Procedure main is 
>
>instr, tokstr : String(1..255);
>
>Begin
>Loop
>    New_Line;
>    Put("*>> ");
>    Get(instr);                 -- this is where it stalls and won't go furthe
r
>    New_Line;
>    Put("*:: ");
>    Put(instr);
>    Exit When instr="quit";
>End Loop;
>End; --main


Hi Cory,

I'm just a newcomer to ADA, so the solution I give you is not 
prefect.  But it seems to work.

Here's the program:


With Text_IO; Use Text_IO;

procedure MAIN is
  package MY_INT_IO is new INTEGER_IO(NATURAL); use MY_INT_IO;
   -- I did this so I can print the length of the string entered

instr : String(1..255);    -- The string entered goes in here
instr_len : NATURAL;       -- The length of that string will be in here.

Begin
Loop
    instr := (others => CHARACTER'FIRST);  -- Fills string full of NUL chars.
    New_Line;
    Put("*>> ");                 -- The prompt
    Get_Line(instr,instr_len);   -- instr -> String to be returned
                                 -- instr_len -> Length of string returned
    New_Line;
    Put("*:: ");                 -- Prints out what you typed
    Put_Line(instr);
    Put(" Length of input string = ");  -- Prints out length of what you typed
    Put(instr_len);
    New_Line;
    exit when instr_len = 0;     -- If you just press <CR> and nothing else
End Loop;                        -- the loop will exit & program will end
End; --main


If you remove the line "instr := (others => CHARACTER'FIRST);" the string
variable does not reinitialize it's self to NUL after each loop, or in the
Put_Line procedure.  So if the string you typed previously is longer than
the current string, you'll see some overlapping.

The line which allows you to actually exit the program:
"exit when instr_len = 0;" I changed to check the length of the 
string instead of for the word "quit".  I did this because I'm not sure
how to compare string values when they are of different lengths.
IE. the constant string "quit" is of length 4, but the variable which
contains the word 'quit', instr, is actually of length 255.....
I believe the var. instr contains the letters 'q' 'u' 'i' 't' PLUS
251 NUL characters.

As I said, I just started learning Ada, so I'm not sure how to check
for this string, any idea's anybody?


Well I hope that helps you.  I know I learned a lot from working on
the problem.




       Norm


-
Norman Russell                         |  Voice: (604)278-3411 ext. 2815
MacDonald Dettwiler and Associates     |  Fax:   (604)278-2117
13800 Commerce Parkway                 |
Richmond, B.C.   CANADA                |  Internet E-Mail: russell@mda.ca
V6V 2J3                                |

             reply	other threads:[~1993-02-04 18:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-02-04 18:39 agate!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-02-03 18:21 simple help with Text_IO 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 14:14 agate!spool.mu.edu!howland.reston.ans.net!bogus.sura.net!darwin.sura.net!
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