Extending a file
Suppose that you want to extend the file “Numbers” to include the squarer
of the numbers 1 to 20 instead of only 1 to 10. You cannot
reopen a
file for
writing, so you will have to:
-
make a new version with a different name;
-
transfer the old file to the new version;
-
add the extra data;
- delete the old file.
Here is how to do it.
First, RUN this program:
10 OPEN #4;“m”;l;“Numbers”: REM for reading
2Q OPEN # 5;“m”;l;“Numbers 1”: REM for writing
30 FOR f=l TO l@
40 INPUT # 4;m;n
50PRlNTX5;m’n
60 NEXT f
74 FOR n=ll TO 20
80 PRINT X 5;n’nX-n
90 NEXT n
100 CLOSE X4:CLOSE Y 5
Now, to check that you have got two files, “Numbers”and “Numbers 1”.
enter:
CAT 1
Next, to delete the old file, enter:
ERASE “m”~l~“Numbers”
I I
To check that it has been deleted, enter:
CAT 1
The file name “Numbers” will have disappeared from the catalogue, and
your new file, “Numbers 1” now contains the numbers from 1 to 20.