comp.lang.ada
 help / color / mirror / Atom feed
From: "DuckE" <nospam_steved94@home.com>
Subject: Re: an infinate loop
Date: Fri, 13 Jul 2001 03:21:16 GMT
Date: 2001-07-13T03:21:16+00:00	[thread overview]
Message-ID: <MOt37.340262$p33.6857463@news1.sttls1.wa.home.com> (raw)
In-Reply-To: tks6i2llqcla15@corp.supernews.com

Hint:
  A file containing the text:

.a

Gives the same error.

SteveD

"Beau" <beau@hiwaay.net> 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
>
>
>





  reply	other threads:[~2001-07-13  3:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-12 21:43 an infinate loop Beau
2001-07-13  3:21 ` DuckE [this message]
2001-07-13 13:57 ` Ted Dennison
2001-07-13 17:01   ` Jeffrey Carter
2001-07-13 18:11     ` Ted Dennison
2001-07-13 22:26       ` Jeffrey Carter
2001-07-16 15:14         ` Marin David Condic
2001-07-17 17:02           ` Matthias Kretschmer
2001-07-17 17:56             ` Marin David Condic
2001-07-17 19:25               ` Ted Dennison
2001-07-19 11:38                 ` Matthias Kretschmer
2001-07-19 14:28                   ` Ted Dennison
2001-07-17 17:13           ` Warren W. Gay VE3WWG
2001-07-14 23:41       ` Darren New
2001-07-16 13:24         ` Ted Dennison
2001-07-16 15:19           ` Marin David Condic
2001-07-13 20:40     ` chris.danx
2001-07-13 22:29       ` Jeffrey Carter
2001-07-14 14:00         ` Robert Dewar
2001-07-14 16:17           ` Negative Logic (was: Re: an infinate loop) Jeffrey Carter
2001-07-17  4:06             ` Robert Dewar
2001-07-17  4:23             ` Robert Dewar
2001-07-16  9:26           ` an infinate loop Philip Anderson
2001-07-19  9:32             ` an infinite [was: infinate] loop AG
2001-07-15 21:18   ` an infinate loop Matthias Kretschmer
2001-07-16 21:59   ` Stephen Leake
2001-07-13 16:48 ` C. Bauman
replies disabled

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