|GNU Octave Manual Version 3|
by John W. Eaton, David Bateman, Søren Hauberg
Paperback (6"x9"), 568 pages
RRP £24.95 ($39.95)
14.2.19 File Positioning
Three functions are available for setting and determining the position of the file pointer for a given file.
- Built-in Function: ftell (fid)
- Return the position of the file pointer as the number of characters
from the beginning of the file fid.
See also fseek, fopen, fclose
- Built-in Function: fseek (fid, offset, origin)
- Set the file pointer to any location within the file fid.
The pointer is positioned offset characters from the origin, which may be one of the predefined variables
SEEK_END(end of file) or strings "cof", "bof" or "eof". If origin is omitted,
SEEK_SETis assumed. The offset must be zero, or a value returned by
ftell(in which case origin must be
Return 0 on success and -1 on error.
See also ftell, fopen, fclose
- Built-in Function: SEEK_SET ()
- Built-in Function: SEEK_CUR ()
- Built-in Function: SEEK_END ()
- Return the value required to request that
fseekperform one of the following actions:
- Position file relative to the beginning.
- Position file relative to the current position.
- Position file relative to the end.
- Built-in Function: frewind (fid)
- Move the file pointer to the beginning of the file fid, returning
0 for success, and -1 if an error was encountered. It is equivalent to
fseek (fid, 0, SEEK_SET).
The following example stores the current file position in the variable
marker, moves the pointer to the beginning of the file, reads
four characters, and then returns to the original position.
marker = ftell (myfile); frewind (myfile); fourch = fgets (myfile, 4); fseek (myfile, marker, SEEK_SET);
|ISBN 095461206X||GNU Octave Manual Version 3||See the print edition|