fseek

Set the file pointer to a location.

Syntax

  • fseek(fid, offset, origin)

  • status = fseek(fid, offset, origin)

Input argument

  • 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 argument

  • 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).

Example

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.

History

VersionDescription

1.0.0

initial version

Author

Allan CORNET

Last updated