comp.lang.ada
 help / color / mirror / Atom feed
From: ada_wizard@toadmail.com
To: comp.lang.ada@ada-france.org
Subject: Re: Word counting
Date: Thu, 11 Dec 2003 21:39:37 -0500
Date: 2003-12-11T21:39:37-05:00	[thread overview]
Message-ID: <mailman.104.1071196773.31149.comp.lang.ada@ada-france.org> (raw)

MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: Internet Messaging Program (IMP) 3.2.1

mutilation@bonbon.net (wave) writes:

> I'm extremely new to ada after coding in a handful of newer
> languages such as PHP and the like. I'm having some difficulties
> with a program I am trying to design using the various functions
> available to me.

Welcome to the One True Language :).

> 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.
> 
>    Max_Chars    :          Integer := 100;  
>    Max_Words    : constant Integer := 15;  
>    Max_Word_Len : constant Integer := 20;  

These make sense.

>    Position,  
>    Number   : Integer := 1;  
>    Length,  
>    Counted_Words : Integer := 0;  

These too.

>    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;  

Now you've lost me. What is stored in Word_Length (1)? the number of
words of length one? It will help you (as well as me) to say that in a
clear comment.

> begin
> 
>    while (not End_Of_File) loop

the parens are not necessary, and give away that you are used to C :).

>       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;

Since this logic does not depend on Position, I can't see that it does
anything useful. 

> <snip rest of program>
> 
> I appreciate any feedback you could give me on this, as it's really
> been annoying me.

What does it do that you did not expect? I know "it doesn't work", but
can you be more specific?

Show an example input, and say what output you expected. 

Process the example input yourself, following your code. That will
help you figure out what it should do, and why it isn't doing it.

In general, your code is fairly good style.

Hope to hear more from you,

-- 
-- Stephe

___________________________________________________________
This mail sent using ToadMail -- Web based e-mail @ ToadNet



             reply	other threads:[~2003-12-12  2:39 UTC|newest]

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

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