fileSeek
fileSeek(p_portx_offsetx_whence) =>t/nil
Description
Sets the position for the next operation to be performed on the file opened on a port. The position is specified in bytes.
Arguments
|
Number of bytes to move forward (or backward with negative argument). |
|
|
|
Value Returned
|
The file does not exist or the position given is out of range for an input file. |
Examples
Let the file test.data contain the single line of text:
0123456789 test xyz
p = infile("test.data")
=> port:"test.data"
fileTell(p)
=> 0
for(i 1 10 getc(p))
=> t ; Skip first 10 characters
fileTell(p)
=> 10
fscanf(p "%s" s)
=> 1 ; s = "test" now
fileTell(p)
=> 15
fileSeek(p 0 0)
=> t
fscanf(p "%d" x)
=> 1 ; x = 123456789 now
fileSeek(p 6 1)
=> t
fscanf(p "%s" s)
=> 1 ; s = "xyz" now
Related Topics
Return to top