From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f3ad228831281c35 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-08 09:40:19 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: getting words from file Date: 8 Mar 2003 09:40:18 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0303080940.3fac2464@posting.google.com> References: <%8oaa.11967$F1.92@sccrnsc04> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1047145218 5534 127.0.0.1 (8 Mar 2003 17:40:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 8 Mar 2003 17:40:18 GMT Xref: archiver1.google.com comp.lang.ada:35069 Date: 2003-03-08T17:40:18+00:00 List-Id: Mark Biggar wrote in message news:<%8oaa.11967$F1.92@sccrnsc04>... > > First you probably want an array of words not singlton variables. But an array has fixed size. You'll need a data structure that expands as necessary, such as a vector or list. The Charles library has both of these data structures: http://home.earthlink.net/~matthewjheaney/charles/index.html For example: with Charles.Strings.Unbounded; package Word_Lists is new Charles.Lists.Unbounded (Charles.Strings.Unbounded.Container_Type); Now you can say something like: declare Words : Word_Lists.Container_Type; begin loop Push_Back (Container => Words, Item => Charles.Strings.To_Container (Length => 0)); declare Word : Charles.Strings.Container_Type renames To_Access (Last (Words)).all; C : Character; begin loop Get (C); if The first is that as the words in the file are variable length, > besides the actual characters of each word you will also need to > store its length (or equivalent) somewhere. You need an unbounded string. You can either use Ada.Strings.Unbounded or Charles.Strings.Unbounded. > The second is related to the first: how are you going to handle a word > that is larger then you expect? Doesn't matter if you use an unbounded string. > The last time I had to solve a similar problem I didn't store the > words in the variables at all. I read the whole file into one big > string and then kept an array of records that recorded the start and end > position of each word into that large string. I then used slicing > to extract the actual characters as needed. Suppose your file is big? How do you even know how big to allocate the array? This problem calls for unbounded data structures, not fixed-length arrays. Note that to use Get_Token, you'll probably have to use Get_Line to read in an entire line, and then extract words from the line. It would be nice to be able to say "read a whitespace-delimited lexeme" from the file; that's that the string extractor for an istream does in C++: string s; while (fin >> s) I should add something like this to Charles.