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,cf677878aa77e0d8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-12 20:21:16 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!enews.sgi.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: Subject: Re: an infinate loop X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Fri, 13 Jul 2001 03:21:16 GMT NNTP-Posting-Host: 24.248.45.203 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 994994476 24.248.45.203 (Thu, 12 Jul 2001 20:21:16 PDT) NNTP-Posting-Date: Thu, 12 Jul 2001 20:21:16 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:9899 Date: 2001-07-13T03:21:16+00:00 List-Id: Hint: A file containing the text: .a Gives the same error. SteveD "Beau" wrote in message news:tks6i2llqcla15@corp.supernews.com... > Hey I am in an infinate loop and don't understand why. here is my problem to > understan exactly what is going down: > assume that a set of sentences is to be processed. Each sentence consists of > a sequence of words, seperated by one or more blank spaces. Write a program > that will read these sentences and count the number of words that have one > letter, two letter, and so on, up to ten letters. > It was working until I put in a loop to catch the end of line because if the > sentence was more than a line, then the words on the end would be counted > together. now the program does the first line perfect and then falls into > the "never-ending" loop. enclosed is the adb file and the data file. put the > file anywhere just type the path in when asked. > ---------- > here is the adb file: > WITH Ada.Text_IO; > USE Ada.Text_IO; > WITH Ada.Integer_Text_IO; > USE Ada.Integer_Text_IO; > > > PROCEDURE Word_Count2 IS > > --declarations needed are as follows > > --variables for file input > > Infile : Ada.Text_IO.File_Type; > > FileName : String(1..80); --for the opening of the file > > Length : Natural; > > --variables for the counters > > WordLength : Natural := 0; > WordCount1 : Natural := 0; > WordCount2 : Natural := 0; > WordCount3 : Natural := 0; > WordCount4 : Natural := 0; > WordCount5 : Natural := 0; > WordCount6 : Natural := 0; > WordCount7 : Natural := 0; > WordCount8 : Natural := 0; > WordCount9 : Natural := 0; > WordCount10 : Natural := 0; > > > --variable for the character > > Letter : Character; > > Pause : Character; --pause to see the results > > > BEGIN --Word_Count > > --print program header > > Put(Item => "Word Count Program. This program will read in "); > New_Line; > Put(Item => "from a text file a set of sentences and count the "); > New_Line; > Put(Item => "amount of words that had 1 letter, 2 letters, "); > New_Line; > Put(Item => "3 letters... up to ten letters."); > New_Line(Spacing => 2); > > --prompt for and read the name of the path for the input file > > Put(Item => "Please key in the path of the input file "); > Put(Item => "for the program:"); > New_Line; > Ada.Text_IO.Get_Line(Item => FileName, Last => Length); > New_Line; > Ada.Text_IO.Open(File => Infile, > Mode => Ada.Text_IO.In_File, > Name => FileName(1..Length)); > > --An outer loop to catch the end of file > > LOOP > EXIT WHEN Ada.Text_IO.End_of_File(File => Infile); > Get(File => Infile, Item => Letter); > Put(Item => "This sentence contained the following: "); > New_Line; > LOOP > EXIT WHEN Ada.Text_IO.End_of_Line(File => Infile); > > -- a nested loop to catch the end of sentence. The end of a sentence can > --be found by looking for .,?,and ! > > LOOP > EXIT WHEN Letter = '.' OR ELSE Letter = '?' OR ELSE Letter = '!'; > > --another nested post-test loop to catch the end of a word. The end of > --a word can be found by looking for blank spaces > > LOOP > CASE Letter IS --if the character variable was a actual letter > --then add one to wordlength > > WHEN 'a'..'z' |'A'..'Z' => > WordLength := WordLength + 1; > WHEN OTHERS => > NULL; > END CASE; > > Get(File => Infile, Item => Letter); > > EXIT WHEN Letter = ' ' OR ELSE Letter = '.' > OR ELSE Letter = '?' OR ELSE Letter = '!'; > > END LOOP; > > --CASE statement to add one to the variable for the number > --letters in each word > > CASE WordLength IS > > WHEN 10 => > WordCount10 := WordCount10 + 1; > WHEN 9 => > WordCount9 := WordCount9 + 1; > WHEN 8 => > WordCount8 := WordCount8 + 1; > WHEN 7 => > WordCount7 := WordCount7 + 1; > WHEN 6 => > WordCount6 := WordCount6 + 1; > WHEN 5 => > WordCount5 := WordCount5 + 1; > WHEN 4 => > WordCount4 := WordCount4 + 1; > WHEN 3 => > WordCount3 := WordCount3 + 1; > WHEN 2 => > WordCount2 := WordCount2 + 1; > WHEN 1 => > WordCount1 := WordCount1 + 1; > WHEN OTHERS => > NULL; > > END CASE; > > WordLength := 0; > > END LOOP; > > --print the number of words that each had 1,2,3,4...10 letters in them > > Put(Item => "The amount of words containing 1 letter was: "); > Put(Item => WordCount1, Width => 2); > New_Line; > Put(Item => "The amount of words containing 2 letter was: "); > Put(Item => WordCount2, Width => 2); > New_Line; > Put(Item => "The amount of words containing 3 letter was: "); > Put(Item => WordCount3, Width => 2); > New_Line; > Put(Item => "The amount of words containing 4 letter was: "); > Put(Item => WordCount4, Width => 2); > New_Line; > Put(Item => "The amount of words containing 5 letter was: "); > Put(Item => WordCount5, Width => 2); > New_Line; > Put(Item => "The amount of words containing 6 letter was: "); > Put(Item => WordCount6, Width => 2); > New_Line; > Put(Item => "The amount of words containing 7 letter was: "); > Put(Item => WordCount7, Width => 2); > New_Line; > Put(Item => "The amount of words containing 8 letter was: "); > Put(Item => WordCount8, Width => 2); > New_Line; > Put(Item => "The amount of words containing 9 letter was: "); > Put(Item => WordCount9, Width => 2); > New_Line; > Put(Item => "The amount of words containing 10 letter was: "); > Put(Item => WordCount10, Width => 2); > New_Line(Spacing => 3); > > Put(Item => "Please press a key to continue: "); > Get(Item => Pause); > New_Line(Spacing => 2); > > WordCount1 := 0; > WordCount2 := 0; > WordCount3 := 0; > WordCount4 := 0; > WordCount5 := 0; > WordCount6 := 0; > WordCount7 := 0; > WordCount8 := 0; > WordCount9 := 0; > WordCount10 := 0; > > END LOOP; > > Ada.Text_IO.Skip_Line(File => Infile, Spacing => 1); > > END LOOP; > > Ada.Text_IO.Close(Infile); > > END Word_Count2; > > ----------------------------- > here is the data file: > > Hello how are you? > I hope this program works. > Maybe it will work because > if it does not, I am in trouble. > Oh well. GoodBye. > -- > ~Beau~ > beau@hiwaay.net > > >