comp.lang.ada
 help / color / mirror / Atom feed
From: "John Clarke" <jclarke@abit.com.au>
Subject: unbound array?
Date: Mon, 26 Jul 2004 12:20:06 +1000
Date: 2004-07-26T12:20:06+10:00	[thread overview]
Message-ID: <41046a70@dnews.tpgi.com.au> (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





             reply	other threads:[~2004-07-26  2:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-26  2:20 John Clarke [this message]
2004-07-26  3:10 ` unbound array? Jim Rogers
2004-07-26  5:43 ` tmoran
2004-07-26 11:37 ` Martin Krischik
2004-07-28 14:09   ` zork
replies disabled

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