User`s guide
4.3 A Sample Random Access Program
This example is an extensive but complete example of random access operation.
The following program reads or writes random records upon command from the
terminal. When the program has been created, assembled, and placed into a file
labeled RANDOM.COM, the CCP level command
A>RANDOM X.DAT
can start the test program. In this case, the RANDOM program looks for a file
X.DAT and, if it finds it, prompts the console for input. If X.DAT is not found,
RANDOM creates the file before displaying the prompt. Each prompt takes the
form:
next command?
and is followed by operator input, terminated by a carriage return. The input com-
mands take the form:
nW nR nF Q
where n is an integer value in the range 0 to 262143, and W, R, F, and Q are simple
command characters corresponding to random write, W, random read, R, random
write with zero fill, F, and quit processing, Q. If you enter a W or F command, the
RANDOM program issues the prompt:
type data:
You then respond by typing up to 127 characters, followed by a carriage return.
RANDOM then writes the character string into the X.DAT file at record n. If you
enter an F command, the RANDOM program fills previously unallocated data blocks
with zeros before writing record n. If you enter the R command, RANDOM reads
record number n and displays the string value at the console. If you enter the Q
command, the X.DAT file is closed, and the program returns to the console com-
mand processor. In the interest of brevity, the only error message is:
err , try again
4-10
4.3 A Sample Random Access Program CP/M 3 Programmer's Guide