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,FREEMAIL_FROM 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-11 19:22:24 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_feed4!attbi.com!attbi_s04.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <4d01ad29.0312111401.32ec5297@posting.google.com> Subject: Re: Word counting X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 12.211.58.135 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s04 1071199343 12.211.58.135 (Fri, 12 Dec 2003 03:22:23 GMT) NNTP-Posting-Date: Fri, 12 Dec 2003 03:22:23 GMT Organization: Comcast Online Date: Fri, 12 Dec 2003 03:22:23 GMT Xref: archiver1.google.com comp.lang.ada:3405 Date: 2003-12-12T03:22:23+00:00 List-Id: The code does not handle a few cases. Ask yourself: What happens if the first character in a line is a space? What happens if the last character in the line is not a space? What happens when two consecutive characters are spaces? There is one other thing that might catch you as well. The Text_Io package in Ada likes to have lines terminated properly. If the last line isn't terminated properly you'll get an End_Error exception. When this happens you'll need to do something to handle the text even though an exception occurred. BTW: Is this a homework assignment? I hope this helps, Steve (The Duck) "wave" wrote in message news:4d01ad29.0312111401.32ec5297@posting.google.com... [snip] > I'm trying to read a file of which each sentence consists of a line of > words, separated obviously by one or more blank spaces. I'm trying to > get it to read these lines of the file and count the number of words > that have one letter, two letters, and so on, up to a maximum of > fifteen letters. > [snip] > > Max_Chars : Integer := 100; > Max_Words : constant Integer := 15; > Max_Word_Len : constant Integer := 20; > > Position, > Number : Integer := 1; > Length, > Counted_Words : Integer := 0; > > Current_Line : String (1 .. Max_Chars); > > type Words_Of_Length is array (Integer range 1 .. 10) of Integer; > type Word_Count_Line is array (Integer range 1 .. 10) of Integer; > Word_Count : Word_Count_Line; > Word_Length : Words_Of_Length; > > begin > > while (not End_Of_File) loop > > Position := 1; > Get_Line(Current_Line,Length); > > for Position in 1..Length loop > if (Current_Line(Position) = ' ') then > Word_Length(Number) := Word_Length(Number) + 1; > Number := Number + 1; > Counted_Words := Counted_Words + 1; > end if; > > Put(Current_Line(Position)); > > end loop; > end loop; > > Put("Counted words: " & Integer'Image(Counted_Words)); > New_Line(5); > > for Index in 1..10 loop > Put(Integer'Image(Index) & " " & > Integer'Image(Word_Length(Index))); > New_Line; > end loop; > > New_Line(5); > > end; > > > I appreciate any feedback you could give me on this, as it's really > been annoying me. > > > > Cheers, > > Mut.