comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Word counting
Date: Fri, 12 Dec 2003 03:22:23 GMT
Date: 2003-12-12T03:22:23+00:00	[thread overview]
Message-ID: <PvaCb.514058$Fm2.498165@attbi_s04> (raw)
In-Reply-To: 4d01ad29.0312111401.32ec5297@posting.google.com

The code does not handle a few cases.
Ask yourself:
  What happens if the first character in a line is a space?
  What happens if the last character in the line is not a space?
  What happens when two consecutive characters are spaces?

There is one other thing that might catch you as well.  The Text_Io package
in Ada likes to have lines terminated properly.  If the last line isn't
terminated properly you'll get an End_Error exception.  When this happens
you'll need to do something to handle the text even though an exception
occurred.

BTW: Is this a homework assignment?

I hope this helps,
Steve
(The Duck)

"wave" <mutilation@bonbon.net> wrote in message
news:4d01ad29.0312111401.32ec5297@posting.google.com...
[snip]
> I'm trying to read a file of which each sentence consists of a line of
> words, separated obviously by one or more blank spaces. I'm trying to
> get it to read these lines of the file and count the number of words
> that have one letter, two letters, and so on, up to a maximum of
> fifteen letters.
>
[snip]
>
>    Max_Chars    :          Integer := 100;
>    Max_Words    : constant Integer := 15;
>    Max_Word_Len : constant Integer := 20;
>
>    Position,
>    Number   : Integer := 1;
>    Length,
>    Counted_Words : Integer := 0;
>
>    Current_Line : String (1 .. Max_Chars);
>
>    type Words_Of_Length is array (Integer range 1 .. 10) of Integer;
>    type Word_Count_Line is array (Integer range 1 .. 10) of Integer;
>    Word_Count : Word_Count_Line;
>    Word_Length : Words_Of_Length;
>
> begin
>
>    while (not End_Of_File) loop
>
>       Position := 1;
>       Get_Line(Current_Line,Length);
>
>       for Position in 1..Length loop
>          if (Current_Line(Position) = ' ')  then
>             Word_Length(Number) := Word_Length(Number) + 1;
>             Number := Number + 1;
>             Counted_Words := Counted_Words + 1;
>          end if;
>
>             Put(Current_Line(Position));
>
>       end loop;
>    end loop;
>
>    Put("Counted words: " & Integer'Image(Counted_Words));
>    New_Line(5);
>
>    for Index in 1..10 loop
>       Put(Integer'Image(Index) & " " &
> Integer'Image(Word_Length(Index)));
>       New_Line;
>    end loop;
>
>    New_Line(5);
>
> end;
>
>
> I appreciate any feedback you could give me on this, as it's really
> been annoying me.
>
>
>
> Cheers,
>
> Mut.





  parent reply	other threads:[~2003-12-12  3:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-11 22:01 Word counting wave
2003-12-11 22:45 ` David C. Hoos
2003-12-12  1:17 ` Jeffrey Carter
2003-12-12  3:22 ` Steve [this message]
2003-12-12 14:33 ` Martin Krischik
  -- strict thread matches above, loose matches on Subject: below --
2003-12-11 22:47 amado.alves
2003-12-11 22:53 amado.alves
2003-12-12  2:39 ada_wizard
2003-12-12  9:49 ` wave
2003-12-12 18:26   ` Jeffrey Carter
2003-12-13  3:40   ` Steve
2003-12-13  6:09     ` tmoran
2003-12-12 12:56 amado.alves
replies disabled

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