[comp.lang.pascal] Ref: Overflow Error

dm2368@eecs1.eecs.usma.edu (Fichten Mark CPT) (05/31/91)

> From: Alex Brown <Alex.Brown@f1020.n391.z1.fidonet.org>
> 
>     I am getting an overflow error after 3 pages are displayed.  Can any tell
> why and how to avoid it in the future.
> 
>    The program is supposed to grab 24 lines of a text and display them
> with a
>    >>>>>>>MORE<<<<<<<<  message at the bottom.
> 
> 

[parts deleted]

> procedure getstring;
>    begin
>   f := 1;
>   while (not eof(ftext)) and (f < 25) do
>     begin
>     readln(ftext, s[f]);
>     inc(f);
>     end;
>   if not eof(ftext) then
>     begin
>     s[25] := '               >>>>>>>>MORE<<<<<<<< ';
>     showpage;
>     readln;
>     end;
>   getstring;
>   end;

The error that I receive when I run your program is Stack Overflow.
This occurs because your procedure getstring has infinite recursion.
Notice that EVERY time the procedure is executed, it will call itself
again.  There is not a 'terminal condition' to exit this recursion.  I
would recommend a control structure that looks something like the
following and avoid recursion completely:

While not EOF(ftext) do
     getstring;

Getstring also fails to null the strings that are not needed for the
last page of output.

Also, your page of text is not being displayed correctly because of 2 
reasons.  First, your loop only goes through the first 24 lines of your 
string array, and second, if you change this to 25 the screen will
scroll up one line and you will lose your top line.  You may want to 
display only 24 lines unless you want to get fancy...

Hope this helps.
--
____________________________________________________________________________

CPT Mark Fichten      | INTERNET: fichten@eecs1.eecs.usma.edu              |
Captain U.S. Army     |           @trotter.edu:dm2368@eecs1.eecs.usma.edu  |
                      | USENET:   rutgers.edu!trotter!eecs1!dm2368         |
                      |           harvard.edu!trotter!eecs1!dm2368         |
____________________________________________________________________________