fseek
Set the file pointer to a location.
📝Syntax
fseek(fid, offset, origin)
status = fseek(fid, offset, origin)
📥Input Arguments
Parameter Description
fid an integer value: file descriptor
offset an integer value: number of bytes to move from origin.
origin an integer value or a string: location in the file.
📤Output Arguments
Parameter Description
status an integer value: 0 or -1 if there is an error.
📄Description

fseek moves the file pointer to the location offset within the file fid.

origin can take as value:

'bof' or -1 : beginning of file.

'cof' or 0 : current position in file.

'eof' or 1 : end of file.

offset may be one of the predefined variables SEEK_CUR (current position, or 0), SEEK_SET (beginning, or -1), or SEEK_END (end of file, or 1).

💡Examples
fileID = fopen([tempdir(), 'fseek.txt'],'wt');
fprintf(fileID, 'son is beautiful.');
fseek(fileID, SEEK_CUR, 'bof');
fprintf(fileID, 'sun');
fclose(fileID);
R = fileread([tempdir(), 'fseek.txt'])
🔗See Also
frewind
🕔Version History
Version Description
1.0.0 initial version
Edit this page on GitHub