The End-of-File internal indicator of the stream is cleared after a call to this function, and all effects from previous calls to ungetc are dropped.
When using fseek on text files with offset values other than zero or values retrieved with ftell, bear in mind that on some platforms some format transformations occur with text files which can lead to unexpected repositioning.
On streams open for update (read+write), a call to fseek allows to switch between reading and writing.
Parameters
- stream
- Pointer to a FILE object that identifies the stream.
- offset
- Number of bytes to offset from origin.
- origin
- Position from where offset is added. It is specified by one of the following constants defined in <cstdio>:
SEEK_SET Beginning of file SEEK_CUR Current position of the file pointer SEEK_END End of file
Return Value
If successful, the function returns a zero value.Otherwise, it returns nonzero value.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
After this code is successfully executed, the file example.txt contains:
This is a sample.
See also
| ftell | Get current position in stream (function) |
| fsetpos | Set position indicator of stream (function) |
| rewind | Set position indicator to the beginning (function) |
