SourcePoint AMD Help

Table of Contents

fseek

Position at a new location in a file.

Syntax

[result =] fseek(file_handle, offset, wherefrom)

Where:

result

specifies a debug variable of type int4 to which the function return value is assigned. If result is not specified, the return value is displayed on the next line of the screen.

file_handle

is a file handle returned from a previous fopen command.

offset

is a signed integer specifying a number of bytes.

wherefrom

0 = beginning of file, 1 = current location, 2 = end of file.

Discussion

The fseek function allows random access within a file. ย The first argument is a file that is open for input or output. The second argument specifies a position. ย The third argument is a "seek code," indicating from what point in the file the offset should be measured.

The return value is 0 if successful or nonzero if an error occurs.

Example

To determine the size of a file:

Command input:

define int4 hFile = fopen("test.dat","r")

fseek(hFile,0,2) ย ย ย ย ย ย ย ย ย // seek to end of file

ftell(hFile)

Result:

000079A8H ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย // file size

Related Topics: