comp.lang.ada
 help / color / mirror / Atom feed
* Problems with Last statment ....
@ 2000-03-14  0:00 Defiant
  2000-03-14  0:00 ` John J Cupak Jr
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Defiant @ 2000-03-14  0:00 UTC (permalink / raw)


hi im writing a program for a uni assignment and it is complete and works
yet i have set the string type to a min of 1 to a max of 20 characters for a
name input...

the problem i am having is i am using the Get_Line(Name, Last) statement to
get the name they feed in and the Put(Name); procedure to output... the
problem is ada compiler grabs whatever extra numerals hex and garbage that
is left in RAM to fill the extra places between 1 and 20... that the name
that was input doesnt fill ....


any suggestions ...

Thanks







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

* Re: Problems with Last statment ....
  2000-03-14  0:00 Problems with Last statment Defiant
@ 2000-03-14  0:00 ` John J Cupak Jr
  2000-03-14  0:00   ` Defiant
  2000-03-14  0:00 ` Frank J. Lhota
  2000-03-14  0:00 ` John English
  2 siblings, 1 reply; 5+ messages in thread
From: John J Cupak Jr @ 2000-03-14  0:00 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 852 bytes --]

I hear about this problem quite a bit from my Ada students.

Reading/Writing fixed-length strings:

Get_Line(Name, Last); -- Reads 0..Last number of characters into Name string
Put         (Name(1..Last)); -- Put ONLY characters just read to output!

Hope this helps!

Yours in Ada,
John

Defiant wrote:

> hi im writing a program for a uni assignment and it is complete and works
> yet i have set the string type to a min of 1 to a max of 20 characters for a
> name input...
>
> the problem i am having is i am using the Get_Line(Name, Last) statement to
> get the name they feed in and the Put(Name); procedure to output... the
> problem is ada compiler grabs whatever extra numerals hex and garbage that
> is left in RAM to fill the extra places between 1 and 20... that the name
> that was input doesnt fill ....
>
> any suggestions ...
>
> Thanks

[-- Attachment #2: Card for John J Cupak Jr --]
[-- Type: text/x-vcard, Size: 364 bytes --]

begin:vcard 
n:Cupak Jr;John J
tel;fax:978.858.4336
tel;work:978.858.1222
x-mozilla-html:TRUE
org:Raytheon Company;Northeast Software Training
version:2.1
email;internet:John_J_Cupak@res.raytheon.com
title:Software Engineering Instructor
adr;quoted-printable:;;50 Apple Hill Road=0D=0AT3MN35;Tewksbury;MA;01876;USA
x-mozilla-cpt:;9904
fn:John J Cupak Jr
end:vcard

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

* Re: Problems with Last statment ....
  2000-03-14  0:00 Problems with Last statment Defiant
  2000-03-14  0:00 ` John J Cupak Jr
@ 2000-03-14  0:00 ` Frank J. Lhota
  2000-03-14  0:00 ` John English
  2 siblings, 0 replies; 5+ messages in thread
From: Frank J. Lhota @ 2000-03-14  0:00 UTC (permalink / raw)


"Defiant" <ithinkiforgot@.bad.memory.com> wrote in message
news:38ce6681.0@news.per.paradox.net.au...
> hi im writing a program for a uni assignment and it is complete and works
> yet i have set the string type to a min of 1 to a max of 20 characters for
a
> name input...
>
> the problem i am having is i am using the Get_Line(Name, Last) statement
to
> get the name they feed in and the Put(Name); procedure to output... the
> problem is ada compiler grabs whatever extra numerals hex and garbage that
> is left in RAM to fill the extra places between 1 and 20... that the name
> that was input doesnt fill ....
>
>
> any suggestions ...
>
> Thanks
>
>
>

The call Get_Line(Name, Last) returns the most recently read line in Name( 1
.. Last ). For example, if the next line is "Hello", then the call
Get_Line(Name, Last) will set Last to 5 and set Name( 1 .. 5 ) to "Hello".
Any character in Name after Name( Last ) is garbage, and therefore should
not be output.

To write only the characters that were actually in the input line, try the
call

    Put ( Name( 1 .. Last ) );

If you want to output the name right padded to 20 characters, you could do
the following:

    Name ( Last + 1 .. Name'Last ) := ( others => ' ');    -- Blank out the
unread portion.
    Put ( Name );

Hope this helps.






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

* Re: Problems with Last statment ....
  2000-03-14  0:00 ` John J Cupak Jr
@ 2000-03-14  0:00   ` Defiant
  0 siblings, 0 replies; 5+ messages in thread
From: Defiant @ 2000-03-14  0:00 UTC (permalink / raw)


THANKS HEAPS !! works like a charm... ill have to remeber this think ill be
using the last statement a bit, thanks!


"John J Cupak Jr" <John_J_Cupak@res.raytheon.com> wrote in message
news:38CE7AD7.7A111DC0@res.raytheon.com...
> I hear about this problem quite a bit from my Ada students.
>
> Reading/Writing fixed-length strings:
>
> Get_Line(Name, Last); -- Reads 0..Last number of characters into Name
string
> Put         (Name(1..Last)); -- Put ONLY characters just read to output!
>
> Hope this helps!
>
> Yours in Ada,
> John
>
> Defiant wrote:
>
> > hi im writing a program for a uni assignment and it is complete and
works
> > yet i have set the string type to a min of 1 to a max of 20 characters
for a
> > name input...
> >
> > the problem i am having is i am using the Get_Line(Name, Last) statement
to
> > get the name they feed in and the Put(Name); procedure to output... the
> > problem is ada compiler grabs whatever extra numerals hex and garbage
that
> > is left in RAM to fill the extra places between 1 and 20... that the
name
> > that was input doesnt fill ....
> >
> > any suggestions ...
> >
> > Thanks
>






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

* Re: Problems with Last statment ....
  2000-03-14  0:00 Problems with Last statment Defiant
  2000-03-14  0:00 ` John J Cupak Jr
  2000-03-14  0:00 ` Frank J. Lhota
@ 2000-03-14  0:00 ` John English
  2 siblings, 0 replies; 5+ messages in thread
From: John English @ 2000-03-14  0:00 UTC (permalink / raw)


Defiant wrote:
> hi im writing a program for a uni assignment and it is complete and works
> yet i have set the string type to a min of 1 to a max of 20 characters for
> a name input...
> 
> the problem i am having is i am using the Get_Line(Name, Last) statement to
> get the name they feed in and the Put(Name); procedure to output... the
> problem is ada compiler grabs whatever extra numerals hex and garbage that
> is left in RAM to fill the extra places between 1 and 20... that the name
> that was input doesnt fill ....

The reason for the Last parameter to Get_Line is it tells you
how many characters were actually read in. To print out just
the characters that you read in, try this:

  Put( Name(1..Last) );

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

end of thread, other threads:[~2000-03-14  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-14  0:00 Problems with Last statment Defiant
2000-03-14  0:00 ` John J Cupak Jr
2000-03-14  0:00   ` Defiant
2000-03-14  0:00 ` Frank J. Lhota
2000-03-14  0:00 ` John English

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