comp.lang.ada
 help / color / mirror / Atom feed
* unbound array?
@ 2004-07-26  2:20 John Clarke
  2004-07-26  3:10 ` Jim Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: John Clarke @ 2004-07-26  2:20 UTC (permalink / raw)


Hello!

I was hoping someone could shed some light. I am writing an ADA program that
reads a file and counts the number of words in the text file and stores the
word length, of each word encountered, in an array. So for instance i have
defined:

size : integer := 100;
type length_type is array (1..size) of integer;
word_length : length_type;

Now, if the text file is: "A rat was here."

Hence, word_length(1) = 1, word_length(2) = 3, word_length(4) = 4 etc...

The problem I am facing is that I don't know how many words I will encounter
in the text file. I do not want to constrain size to 100 as I have above. I
know I can use unconstrained array type, but this also doesn't solve the
problem as an unconstrained array requires a predefined size assigned prior
to assigning values to it.

I know that size will never be greater than the number of characters in the
text file. But it would be a little ridiculous assigning "size" = "number of
characters in text file".

How can this problem be solved? Any help would be great.

Thanks
Peter





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-07-28 14:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-26  2:20 unbound array? John Clarke
2004-07-26  3:10 ` Jim Rogers
2004-07-26  5:43 ` tmoran
2004-07-26 11:37 ` Martin Krischik
2004-07-28 14:09   ` zork

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