FSEEK()

Positions the file pointer in a file.

Syntax

FSEEK( <nHandle>, <nOffset>, [<nOrigin>] ) --> nPosition

Arguments

<nHandle> DOS file handle.

<nOffset> The number of bytes to move.

<nOrigin> The relative position in the file.

Returns

<nPosition> the current position relative to begin-of-file

Description

This function sets the file pointer in the file whose DOS file handle is and moves the file pointer by bytes from the file position designated by . The returned value is the relative position of the file pointer to the beginning-of-file marker once the operation has been completed.

is the file handle number. It is obtained from the FOPEN() or FCREATE() function.

The value of is the number of bytes to move the file pointer from the position determined by .The value of may be a negative number, suggesting backward movement.

The value of designates the starting point from which the file pointer should he moved, as shown in the following table:

<nOrigin>fileio.chFile position
0FS_SETBeginning of file
1FS_RELATIVECurrent file pointer position
2FS_ENDEnd of file

If a value is not provided for , it defaults to 0 and moves the file pointer from the beginning of the file.

Examples

// here is a function that read one text line from an open file
// nH = file handle obtained from FOPEN()
// cB = a string buffer passed-by-reference to hold the result
// nMaxLine = maximum number of bytes to read
#define EOL HB_OSNEWLINE()
FUNCTION FREADln( nH, cB, nMaxLine )
LOCAL cLine, nSavePos, nEol, nNumRead
cLine := space( nMaxLine )
cB := ''
nSavePos := FSEEK( nH, 0, FS_RELATIVE )
nNumRead := FREAD( nH, @cLine, nMaxLine )
IF ( nEol := AT( EOL, substr( cLine, 1, nNumRead ) ) ) == 0
cB := cLine
ELSE
cB := SUBSTR( cLine, 1, nEol - 1 )
FSEEK( nH, nSavePos + nEol + 1, FS_SET )
ENDIF
RETURN nNumRead != 0

Status

Ready

Compliance

This function is CA-Clipper compliant.

Files

Library is rtl Header is fileio.ch

See Also