next up previous contents
Next: SPRINTF Formated String Output Up: Input/Ouput Functions Previous: FEOF End Of File   Contents

Subsections

FSEEK Seek File To A Given Position

Usage

Moves the file pointer associated with the given file handle to the specified offset (in bytes). The usage is

  fseek(handle,offset,style)

The handle argument must be a value and active file handle. The offset parameter indicates the desired seek offset (how much the file pointer is moved in bytes). The style parameter determines how the offset is treated. Three values for the style parameter are understood:

The offset can be positive or negative.

Example

The first example reads a file and then ``rewinds'' the file pointer by seeking to the beginning. The next example seeks forward by 2048 bytes from the files current position, and then reads a line of 512 floats.

--> fp = fopen('test.dat','rb');
--> x = fread(fp,[1,inf],'float');
--> fseek(fp,0,'bof');
--> y = fread(fp,[1,inf],'float');
--> who x y
  Variable Name      Type   Flags             Size
              x     float                    [1 1024]
              y     float                    [1 1024]
--> fseek(fp,2048,'cof');
--> x = fread(fp,[512,1],'float');
Error: Insufficient data remaining in file to fill out requested size


next up previous contents
Next: SPRINTF Formated String Output Up: Input/Ouput Functions Previous: FEOF End Of File   Contents
Samit K. Basu 2005-03-16