fseek function is used to move the file position to a desired location within the file. It takes the following form:
fseek(file ptr, offset, position)
File ptr is a pointer to the file concerned, offset is a number variable of type long and position is an integer number. The offset specifics the number of positions(bytes) to the moved from the location specified by position.
The position can take one of the following three values
Values -----------Meaning
0 --------------Beginning of file
1 --------------Current position
2 ----------------End of file
offset may be positive meaning move forwards or negative meaning move backwards.
The following examples illustrate the operation of the fseek function:
Statement ----------------------------Meaning
fseek(fp,0L,0) ------------------Go to beginning
fseek(fp, 0L, 1) -------------Stays at current position
fseek(fp, 0L, 2) --------Go to end of the file, past the last character of the file
fseek(fp, m, 0) -----------Move to (m+1)th byte in the file
fseek(fp, m, 1) ---------Go forwared by m bytes
fseek(fp, -m, 1) ----Go backward by m bytes from the current position
fseek(fp, - m, 2) ------Go backward by m bytes from the end
fseek(file ptr, offset, position)
File ptr is a pointer to the file concerned, offset is a number variable of type long and position is an integer number. The offset specifics the number of positions(bytes) to the moved from the location specified by position.
The position can take one of the following three values
Values -----------Meaning
0 --------------Beginning of file
1 --------------Current position
2 ----------------End of file
offset may be positive meaning move forwards or negative meaning move backwards.
The following examples illustrate the operation of the fseek function:
Statement ----------------------------Meaning
fseek(fp,0L,0) ------------------Go to beginning
fseek(fp, 0L, 1) -------------Stays at current position
fseek(fp, 0L, 2) --------Go to end of the file, past the last character of the file
fseek(fp, m, 0) -----------Move to (m+1)th byte in the file
fseek(fp, m, 1) ---------Go forwared by m bytes
fseek(fp, -m, 1) ----Go backward by m bytes from the current position
fseek(fp, - m, 2) ------Go backward by m bytes from the end