UP ONE LEVEL: ENCM 339 Fall 2001 Home Page
Making an input/output record may also be helpful when you are trying to debug a defective program. A printout of input and output may give some clues about where things start to go wrong. (However, it should be pointed out that a debugger like gdb is a much more powerful tool.)
If you are using your own computer to do the assignments, you may produce an input/output record on your home machine. If you do so, there is no need to move your program back to the Linux lab to make and print a termrec file.
When you run termrec everything the computer sends to the terminal screen (prompts and program output, mainly) and everything the user types in (shell commands and program input, mainly) gets saved in a text file.
termrec filewhere file is the name of the file you want to store the session record in. If you forget to specify file, the session record will be stored in a file called typescript.
After you start termrec, you get a new shell prompt, which contains <termrec> to remind you that termrec is running.
#include <iostream.h>
int main()
{
int a, b;
cout << "Please enter a value for the int variable a: ";
cin >> a;
cout << "Please enter a value for the int variable b: ";
cin >> b;
if (!cin)
cout << "\nI am sorry, but I could not read all your input." << endl;
else {
cout << "You entered "
<< a << " for a and " << b << " for b." << endl;
cout << "The sum of those numbers is " << (a + b) << '.' << endl;
}
return 0;
}
She compiles and links the program with g++w.
Then she starts termrec to record an interactive session
with the program.
After running the program and exiting from termrec
she uses more to display
the record she has created.
Below is a picture of the screen after all this has been done.
There are annotations in the picture
to help you
distinguish actual prompts, commands,
and program output from copies of prompts, commands,
and program output stored in a text file.
(Warning: The example
is based on the 1997 configuration of the Common Core Linux systems,
so in the ENEL lab in 2001
minor things, such as the shell prompt, may differ
from what appears below.)