Creating a Program Log
You are often asked to generate a log of the execution of your programs; i.e. a script
showing everything the user enters along with the corresponding program output.
Looking at the script would therefore be the same as looking at the screen during the
execution of the program. The following steps allow you to do this easily and neatly:
- Write the program to solve the problem at hand without regard to logs at first
(i.e. screen input/output). Run your program and test thoroughly using various
inputs until you are satisfied it is correct.
- Add an OPEN statement at the top of the program to associate a filename
(e.g. myLog.txt) with a unit number (e.g. 55).
- Add a WRITE (55, ... after each PRINT ... statement in your program. This way,
all your prompts and outputs appear on the log file in addition to appearing on
the screen. The WRITE statement should have the same output list and format
label (if any) as the PRINT statement.
- Add a WRITE (55, ... after each READ ... statement in your program. This way,
all your inputs are echoed on the log file. The WRITE statement should have
the same output list and format label (if any) as the READ statement.
- Run the program as many times as needed, supplying different inputs.
Everything appearing on the screen will also appear on the log file.
Note that the program must have an input loop to allow you to make your input,
capture the output, and then make another input and so on until a sentinel is
detected. If not; i.e. if the program needs to be re-run for each input, the
generated log file will be overwritten each time (unless renamed) and you will
end up with the log of the last run only. There is no option in this compiler
to append the output to an existing file.