comp.lang.ada
 help / color / mirror / Atom feed
From: gerhard.nospam@bigfoot.de (Gerhard Häring)
Subject: Re: a little help
Date: Tue, 16 Oct 2001 11:50:21 +0200
Date: 2001-10-16T11:50:21+02:00	[thread overview]
Message-ID: <slrn9snplt.ja.gerhard.nospam@lilith.hqd-internal> (raw)
In-Reply-To: 9qgrgh$1f10$1@newsreader1.mclink.it

On Tue, 16 Oct 2001 10:39:14 +0200, F <phosphorus@libero.it> wrote:
>Hello world,
>          i'm trying to learn Ada but i've a lot of problems with the
>operations with strings.
>In particular i've a procedure for the input:
>
>type st is new string;
>procedure leggis (j: in out st) is
>    c:character;
>begin
>    while not end_of_line loop
>        get(c); b(ind):=c; ind:=ind+1;
>    end loop;
>end leggis;
>
>
>when i call the first time this procedure i obtain the input string but the
>second time nothing happens.....
>I think that character return remains in the keyboard buffer, how can I
>resolve this problem?????

Looks like you're not telling us the whole story. Where do the b and ind
variables come from? Looks like they *should* be put in the procedure
but they're now declared and initialized outside in (global?) variables.
This means you get so-called side-effects when running the procedure:
the procedure isn't self-contained but changes state elsewhere. This
usually leads to bugs sooner or later.

Solution: put all variables into the proecedure and initialize them
there, too. ind should be initialized to 0 if I see this correctly.

If you want to improve the code even further, you can make the j
parameter "out" instead of "in out", but even better would be to make
the whole thing a function instead.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



  reply	other threads:[~2001-10-16  9:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-16  8:39 a little help F
2001-10-16  9:50 ` Gerhard Häring [this message]
2001-10-16 12:23   ` F
2001-10-16 15:47     ` Gerhard Häring
2001-10-16 15:46   ` Martin Dowie
2001-10-16 15:29 ` Ted Dennison
2001-10-17  7:11   ` F
2001-10-17 14:26     ` Ted Dennison
2001-10-17 10:00 ` Preben Randhol
replies disabled

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