From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: Terminating a task
Date: Tue, 15 Jul 2003 22:37:28 GMT
Date: 2003-07-15T22:37:28+00:00 [thread overview]
Message-ID: <3F148227.6060702@attbi.com> (raw)
In-Reply-To: 1ec946d1.0307141545.2175a770@posting.google.com
Matthew Heaney wrote:
> Here is a simplified version of the program, which closely follows the
> gcc example:
>
>
> with Ada.Text_IO; use Ada.Text_IO;
> with Ada.Characters.Latin_1; use Ada.Characters;
> with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
>
> procedure WC is
>
> Line : String (1 .. 133);
> Last : Natural;
>
> NL, NW, NC : Integer'Base := 0;
>
> Word : Boolean := False;
>
> begin
>
> while not End_Of_File loop
>
> Get_Line (Line, Last);
>
> NC := NC + Last;
>
> for I in Line'First .. Last loop
> if Line (I) = Latin_1.Space or Line (I) = Latin_1.HT then
> Word := False;
>
> elsif not Word then
> Word := True;
> NW := NW + 1;
>
> end if;
> end loop;
>
> if Last < Line'Last then
> Word := False;
> NL := NL + 1;
> end if;
>
> end loop;
>
> Put ("NL="); Put (NL, Width => 0); New_Line;
> Put ("NW="); Put (NW, Width => 0); New_Line;
> Put ("NC="); Put (NC, Width => 0); New_Line;
>
> end WC;
If you change:
if Last < Line'Last then...
to:
if End_of_Line then
Word := False;
NL := NL + 1;
end if;
maybe that will end the 'discussion' about whether it is possible to
count lines properly in Ada. Oh, you might want to stick:
exit when End_of_File;
after the call to Get_Line. Of course the need to do that or not
depends on the number of lines and characters you want to count for the
implict End_of_Page at the end of the file. Notice that with these
changes your program should work fine even if you set Line to
String(1..10);
--
Robert I. Eachus
�In an ally, considerations of house, clan, planet, race are
insignificant beside two prime questions, which are: 1. Can he shoot? 2.
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and
Steve Miller.
next prev parent reply other threads:[~2003-07-15 22:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-12 14:03 Terminating a task kat-Zygfryd
2003-07-12 14:37 ` kat-Zygfryd
2003-07-14 9:34 ` Craig Carey
2003-07-14 23:45 ` Matthew Heaney
2003-07-15 17:49 ` Craig Carey
2003-07-15 18:30 ` David C. Hoos
2003-07-16 5:26 ` Matthew Heaney
2003-07-15 22:37 ` Robert I. Eachus [this message]
2003-07-16 5:00 ` Matthew Heaney
2003-07-16 18:19 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox