STRINGS
The following program illustrates using STRINGS (a sequence of
characters) in a DG Pascal program. STRING is type defined
as a packed array of type char.
Message is then declared as the same type as STRING, ie, a packed array of characters, elements numbered one to eight.
PROGRAM DGSTRING (INPUT, OUTPUT);
TYPE STRING = PACKED ARRAY [1..8] OF CHAR;
VAR MESSAGE : STRING;
BEGIN
WRITELN('HELLO BRIAN.');
MESSAGE := '12345678';
WRITELN('THE MESSAGE IS ', MESSAGE)
END.
Turbo Pascal, how-ever, allows an easier use of character strings by providing a new keyword called STRING. Using STRING, you can add a parameter (how many characters) specifying the string length. Consider the above program re-written for turbo pascal.
PROGRAM TPSTRING (INPUT, OUTPUT);
VAR MESSAGE : STRING[8];
BEGIN
WRITELN('HELLO BRIAN.');
MESSAGE := '12345678';
WRITELN('THE MESSAGE IS ', MESSAGE)
END.
Obviously, the turbo pascal version is easier to use. BUT, the following program shows a similar implementation for use on the DG.
PROGRAM DGSTRING2 (INPUT, OUTPUT);
CONST $STRINGMAXLENGTH = 8; {defines maxlength of a string}
%INCLUDE 'PASSTRINGS.IN'; {include code to handle strings}
VAR MESSAGE : $STRING_BODY;
BEGIN
WRITELN('HELLO BRIAN.');
MESSAGE := '12345678';
WRITELN('THE MESSAGE IS ', MESSAGE)
END.