home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
m2t-2.zip
/
ANSWERS
/
CH08E1.MOD
< prev
next >
Wrap
Text File
|
1989-01-18
|
2KB
|
67 lines
(* Chapter 8 - Programming exercise 1 *)
MODULE CH08E1;
FROM FileSystem IMPORT Lookup, Close, File, Response, ReadChar;
FROM InOut IMPORT Write, WriteString, WriteCard, ReadString,
WriteLn, EOL;
VAR NameOfFile : ARRAY[1..15] OF CHAR;
InFile : File;
InLine : ARRAY[1..80] OF CHAR; (* Note, There is no check
for a spill out of
this line. Assumes all
lines are shorter. *)
Character : CHAR;
Count : CARDINAL;
LineCount : CARDINAL;
BEGIN
REPEAT (* repeat until a good filename is found *)
WriteLn;
WriteString("Enter name of file to display ---> ");
ReadString(NameOfFile);
Lookup(InFile,NameOfFile,FALSE);
UNTIL InFile.res = done; (* good filename found *)
LineCount := 0;
WriteLn;
Count := 0;
InLine[1] := 0C; (* String terminator *)
REPEAT (* character read/display loop - quit at InFile.eof *)
ReadChar(InFile,Character);
IF NOT InFile.eof THEN
IF Character # EOL THEN
Count := Count + 1;
InLine[Count] := Character;
InLine[Count + 1] := 0C; (* String terminator *)
ELSE
WriteCard(Count,5);
WriteString(" ");
WriteString(InLine);
WriteLn;
Count := 0;
InLine[1] := 0C; (* String terminator *)
LineCount := LineCount + 1;
END;
END;
UNTIL InFile.eof; (* quit when eof is found *)
Close(InFile);
WriteLn;
WriteString("There were");
WriteCard(LineCount,5);
WriteString(" lines in the file.");
WriteLn;
END CH08E1.
(* Result of execution
(The selected file is listed on the monitor, with the character
count listed for each line, and the total number of lines.)
*)