comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <jrcarter@acm.org>
Subject: Re: string operations
Date: 2000/11/18
Date: 2000-11-18T00:00:00+00:00	[thread overview]
Message-ID: <3A16C006.B79A599@acm.org> (raw)
In-Reply-To: 3A16A4D5.CE941970@t-online.de

Margit Gut wrote:
> I try to read a string from the keyboard and then I want to write a
> recursiv function to turn the characters  from the end to the beginning.

The requirement that this be a recursive function sounds like a homework
problem.

> 
> I fetch the string with Get_Line. I declared the string with
> Sstring : string(1..255);
> So whatever I try, the string'Length is always 255.

Given the declaration

S : String (1 .. 255);

S'Length is always 255. This is the definition of the 'Length attribute
on an array object.

Look carefully at the description of Get_Line in the ARM (A.10.7),
especially the meaning of the Last parameter, and then read about slices
(ARM 4.1.2). You can find the ARM on line at

http://www.adapower.com/rm95/index.html

If the string read by Get_Line is shorter than its Item parameter, it is
stored in Item (Item'First .. Last). Thus, after executing

Get_Line (Item => S, Last => Last);

the string of interest is in the slice

S (S'First .. Last)

>  My next poblem is, how to do a correct Function, that calls itselve.

A function calls itself exactly the same way that any other statement
calls the function:

function F (N : Positive) return Positive is
begin -- F
   if N <= 1 then
      return N;
   else
      return N * F (N - 1);
   end if;
end F;

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail





  reply	other threads:[~2000-11-18  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-18  0:00 string operations Margit Gut
2000-11-18  0:00 ` Jeff Carter [this message]
2000-11-19  0:00 ` Robert Dewar
2000-11-20  0:00   ` Anders Wirzenius
2000-11-20  0:00     ` Robert Dewar
2000-11-21  6:30       ` Anders Wirzenius
2000-11-24  0:00         ` Margit Gut
2000-11-24  0:00         ` Margit Gut
  -- strict thread matches above, loose matches on Subject: below --
2000-11-24  0:00 String operations Margit Gut
replies disabled

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