comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: Word counting
Date: Sat, 13 Dec 2003 03:40:11 GMT
Date: 2003-12-13T03:40:11+00:00	[thread overview]
Message-ID: <vSvCb.379036$ao4.1266025@attbi_s51> (raw)
In-Reply-To: 4d01ad29.0312120149.ddda940@posting.google.com

"wave" <mutilation@bonbon.net> wrote in message
news:4d01ad29.0312120149.ddda940@posting.google.com...
> Hello again, christ six replies already :)
>
> Anyway, I've taken most of your advice and I've rethought the pseudo
> code for the program.
>
> While not the end of the file
> Read the next line from the file
> Move the cursor one place and if character is within a..Z boundaries
> that character is stored in an array word_length(number) for that word
> length
> if the chracter is a space, then we've hit the end of that word
> length so increment our word length to search for by 1 (number). we've
> also hit the end of a word to increment our word count.
> End of loop;
>
Here's the way I would pseudo code this (I don't think yours quite works).

  While its not the end of the file
    Read a line from the file
    Initialize "current number of characters in word" to 0
    For each character in the line loop
    If a character is a space
      If the current number of characters in word is > 0
        Increment the length count using the current number of characters in
word
        Set the current number of characters in word to 0
      End If
    else
      Increment the current number of characters in word
    end if
    End Loop
    If the current number of characters in word is > 0
      Increment the length count using the current number of characeter in
word
    End If
  End While

I coded this logic in Ada and it appears to work.
Your original code didn't initialize the array of counts (GNAT warned about
this).

BTW: This was more of an algorithm question than an Ada question.  I'll
leave the coding up to you.

Steve
(The Duck)

>
> I realise this is a complete mess and I'm thinking about scrapping the
> whole thing and starting again. For some reason I'm not managing to
> get my head around it and I'm unsure why.
>
> I appreciate your patience up to this far.
>
> Cheers again,
> Mut.





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

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-12  2:39 Word counting ada_wizard
2003-12-12  9:49 ` wave
2003-12-12 18:26   ` Jeffrey Carter
2003-12-13  3:40   ` Steve [this message]
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