Pointer to the file stream for which the file position is to be set
2nd Parameter Type : const fpos_t *
A pointer to a constant `fpos_t` object, used to store or set a file position. The `const` qualifier ensures that the pointed-to position cannot be modified through this pointer.
2nd Parameter
Pointer to an `fpos_t` object containing the position to set for the file stream
Read more about parameters of fsetpos in parameters section
The fsetposfunction in C language Sets the file position of the stream based on the position given by fpos_t.
The fsetpos function sets the file position indicator for the stream pointed to by stream according to the value of the object pointed to by pos, which is a pointer to an fpos_t object that specifies the position. The function is typically used in conjunction with fgetpos to restore a position previously obtained. On successful completion, the function clears the end-of-file indicator for the stream and undoes any effects of ungetc on the same stream.
The fsetposfunction takes 2
parameters:
•
FILE * `stream`: Pointer to the file stream for which the file position is to be set
•
const fpos_t * `pos`: Pointer to an `fpos_t` object containing the position to set for the file stream
Sets the file position of the specified file stream to the location specified by `pos`. The `fpos_t` object should have been obtained using `fgetpos`. Returns `0` on success or a nonzero value on error.
The fsetpos function return value :
Returns 0 if successful, or non-zero if an error occurred
Output
This example demonstrates the basic usage of `fsetpos` in conjunction with `fgetpos`. It reads the first two lines of a file, saves the position after the first line, and then restores that position to read the second line again.