seek() -- change the position within an open file
The seek-command changes the position, where the next input (or peek) statement will read from an open file. Usually files are read from the beginning to the end sequentially; however sometimes you may want to depart from this simple scheme. This can be done with the seek-command, allowing you to change the position, where the next piece of data will be read from the file.
seek accepts two or three arguments: The first one is the number of an already open file. The second one is the position where the next read from the file will start. The third argument is optional and specifies the the point from where the position (the second argument) will count. It can be one of:
begin -- Count from the beginning of the file.
end -- Count from the end of the file.
here -- Count from the current position within the file.
for a=1 to 10
if (a<10) print #1,""
if (mod(i,1000)=0) print "."
This example increments randomly one of ten counters (in the array count()); however, the result is always kept and updated within the file count.dat, so even in case of an unexpected interrupt, the result will not be lost.
tell, open, print, peek