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,97643ec695b9bf73 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-12 22:09:29 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!attbi_feed3!attbi.com!attbi_s51.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Word counting References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 24.6.133.123 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s51 1071295768 24.6.133.123 (Sat, 13 Dec 2003 06:09:28 GMT) NNTP-Posting-Date: Sat, 13 Dec 2003 06:09:28 GMT Organization: Comcast Online Date: Sat, 13 Dec 2003 06:09:28 GMT Xref: archiver1.google.com comp.lang.ada:3433 Date: 2003-12-13T06:09:28+00:00 List-Id: You need to read in a line. You want to scan the line, including just off both ends, looking for word/non-word transitions. On the non-word => word transitions, you want to note the start of the word. On the word => non-word transitions, you want to see how long it's been since the last non-word => word transition, and increment a counter for that length. --You need to read in a line. Line : String(1 .. 80); Last : Natural; --You want to scan the line, including just off both ends, --looking for word/non-word transitions. Currently_In_Word: Boolean; --On the non-word => word transitions, you want to note the start of the word. Start_Index: Positive; --On the word => non-word transitions, you want to see how long it's been --since the last non-word => word transition, Length : Integer range Line'range; --and increment a counter for that length. Counter : array (Line'range) of Natural := (others => 0); begin while not Ada.Text_Io.End_Of_File loop --You need to read in a line. Ada.Text_Io.Get_Line(Line, Last); Currently_In_Word := False; --You want to scan the line for I in 0 .. Last + 1 loop --looking for word/non-word transitions. if (I in 1 .. Last and then Line(I) /= ' ') then if not Currently_In_Word then --On the non-word => word transitions, Currently_In_Word := True; --you want to note the start of the word. Start_Index := I; end if; else if Currently_In_Word then --On the word => non-word transitions, Currently_In_Word := False; --you want to see how long it's been since the last non-word => word --transition, Length := I - Start_Index; --and increment a counter for that length. Counter(Length) := Counter(Length) + 1; end if; end if; end loop; end loop;