Quote
cla...@intergate.bc.ca (Jason Clarke) wrote:
>I'm trying to write a procedure that will take a string and add it on to the
>end of an text array. If the array was named array, and the string named
>string, then I'm trying to use a statement like "array = array + string".
>I've found that this obviously does not work, and looking this up in the "text
>book" they gave us is next to impossible. Please will some kind hearted person
>e-mail me with an idea or two on how to accomplish this task. I would
>appreciate it greatly.
>Thanks!
>--
> - Jason Clarke
>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The user TYPEs may be passed as VAR parameters to a procedure if
needed.
Program ArrayExtend;
{ Turbo v6.0 <clifp...@airmail.net> Aug 1, 1997
This shows an easy way to do what you want. If you wish to store array
elements somewhat randomly (instead of serially as here), just keep
up with the array index.
Should you run out of stack memory for the array, you can use an array
of pointers instead of s80. The much shorter pointers point to the
memory locations (in the heap) that store the strings. }
CONST ArrayMax = 5; {for test purposes. Increase as needed}
TYPE
range = 0..ArrayMax; {indx = 0 is used to signal quit.
a[0] is used as an input buffer.}
s80 = String[80];
arry = Array[range] of s80;
VAR
a:arry;
n, indx:range; {positive integers from 0 to ArrayMax}
done:Boolean;
BEGIN
Writeln; Writeln;
Repeat
indx := 0;
Writeln('Terminate by just pressing <Enter>');
Repeat
Writeln('Enter a line of text below:') ;
Readln( a[0] );
If a[0] <> '' then {store in next array element}
Begin
Inc(indx);
a[indx] := a[0];
End;
done := (a[0] = '') OR (indx = ArrayMax);
Writeln;
Until done;
If not (indx = 0) then {display array contents}
Begin
Writeln;
If indx = ArrayMax then Writeln('ARRAY FULL');
Writeln('In order of entry, the array stores: ');
Writeln;
For n := 1 to indx Do Writeln(a[n]);
Writeln;
End;
Until indx = 0;
END.