From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=BAYES_40,MSGID_SHORT autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 4 Feb 93 18:39:30 GMT 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 Message-ID: <4005@mdavcr.mda.ca> List-Id: In article 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 , >but nothing happens. What should happen is that this: > >*:: > >should be printed to the console, but isn't. And nothing >happens. The input prompt: > >*>> > >is printed, then I can type something, but after >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 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 |