Modula-2 || Compiler & Tools || Library || Search Engine
CONST EOL = 12C;
VAR Done: BOOLEAN; VAR termCH: CHAR;
PROCEDURE Read(VAR ch: CHAR); PROCEDURE ReadString(VAR s: ARRAY OF CHAR); PROCEDURE ReadCard(VAR c: CARDINAL); PROCEDURE ReadInt(VAR i: INTEGER);
PROCEDURE Write(ch: CHAR); PROCEDURE WriteLn; PROCEDURE WriteString(s: ARRAY OF CHAR); PROCEDURE WriteInt(x: INTEGER; n: CARDINAL); PROCEDURE WriteCard(x: CARDINAL; n: CARDINAL); PROCEDURE WriteOct(x: CARDINAL; n: CARDINAL); PROCEDURE WriteHex(x: CARDINAL; n: CARDINAL);
Read reads a character and stores it in ch.
ReadString reads a sequence of characters not containing blanks nor control characters. Leading blanks and tabs are ignored. The terminating character is assigned to termCH. When str is filled up to its limit during reading, ReadString returns after reading one additional character that is assigned to termCH.
ReadCard and ReadInt read a string and convert it to cardinal or integer, respectively. Leading blanks are ignored. The terminating character is assigned to termCH.
Write writes ch to stdout.
WriteLn is equivalent to Write(EOL).
WriteString writes s to stdout.
WriteInt and WriteCard write an integer or cardinal, respectively, x with at least n characters on stdout. If n is greater than the number of digits needed, blanks are added preceding the number.
WriteOct and WriteHex write a cardinal number in octal/hexadecimal format.
WriteString("i = "); ReadInt(i); WriteString("j = "); ReadInt(j);
Note that the semantics of the remaining operations is slightly different from the Lilith implementation due to the line-oriented input mode under UNIX. On Lilith, the example above has to be extended with explicit invocations of WriteLn because line terminators were neither to be typed (every other non-digit would work as well) nor echoed:
WriteString("i = "); ReadInt(i); WriteLn; WriteString("j = "); ReadInt(j); WriteLn;
The current implementation is due to Andreas Borchert.
Modula-2 || Compiler & Tools || Library || Search Engine