home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / m2t-2.zip / ANSWERS / CH08E1.MOD < prev    next >
Text File  |  1989-01-18  |  2KB  |  67 lines

  1.                             (* Chapter 8 - Programming exercise 1 *)
  2. MODULE CH08E1;
  3.  
  4. FROM FileSystem IMPORT Lookup, Close, File, Response, ReadChar;
  5. FROM InOut      IMPORT Write, WriteString, WriteCard, ReadString,
  6.                                                        WriteLn, EOL;
  7.  
  8. VAR  NameOfFile : ARRAY[1..15] OF CHAR;
  9.      InFile     : File;
  10.      InLine     : ARRAY[1..80] OF CHAR;  (* Note, There is no check
  11.                                               for a spill out of
  12.                                               this line.  Assumes all
  13.                                               lines are shorter.   *)
  14.      Character  : CHAR;
  15.      Count      : CARDINAL;
  16.      LineCount  : CARDINAL;
  17.  
  18. BEGIN
  19.    REPEAT                  (* repeat until a good filename is found *)
  20.       WriteLn;
  21.       WriteString("Enter name of file to display ---> ");
  22.       ReadString(NameOfFile);
  23.       Lookup(InFile,NameOfFile,FALSE);
  24.    UNTIL InFile.res = done;                  (* good filename found *)
  25.  
  26.    LineCount := 0;
  27.    WriteLn;
  28.    Count := 0;
  29.    InLine[1] := 0C;                            (* String terminator *)
  30.    REPEAT       (* character read/display loop - quit at InFile.eof *)
  31.       ReadChar(InFile,Character);
  32.       IF NOT InFile.eof THEN
  33.          IF Character # EOL THEN
  34.             Count := Count + 1;
  35.             InLine[Count] := Character;
  36.             InLine[Count + 1] := 0C;           (* String terminator *)
  37.          ELSE
  38.             WriteCard(Count,5);
  39.             WriteString("  ");
  40.             WriteString(InLine);
  41.             WriteLn;
  42.             Count := 0;
  43.             InLine[1] := 0C;                   (* String terminator *)
  44.             LineCount := LineCount + 1;
  45.          END;
  46.       END;
  47.    UNTIL InFile.eof;                      (* quit when eof is found *)
  48.    Close(InFile);
  49.  
  50.    WriteLn;
  51.    WriteString("There were");
  52.    WriteCard(LineCount,5);
  53.    WriteString(" lines in the file.");
  54.    WriteLn;
  55. END CH08E1.
  56.  
  57.  
  58.  
  59.  
  60. (* Result of execution
  61.  
  62. (The selected file is listed on the monitor, with the character
  63.   count listed for each line, and the total number of lines.)
  64.  
  65. *)
  66.  
  67.