C examples for stdio.h:fseek
function
<cstdio> <stdio.h>
Reposition stream position indicator
int fseek ( FILE * stream, long int offset, int origin );
Parameter | Description |
---|---|
stream | FILE object. |
offset | offset |
origin | Position used as reference for the offset. |
origin could be the following:
Constant | Reference position |
---|---|
SEEK_SET | Beginning of file |
SEEK_CUR | Current position of the file pointer |
SEEK_END | End of file |
On success, the function returns zero.
Otherwise, it returns non-zero value.
If a read or write error occurs, the error indicator (ferror) is set.
#include <stdio.h> int main ()//from w w w . j a v a 2 s. c o m { FILE * pFile; pFile = fopen ( "example.txt" , "wb" ); fputs ( "This is a test test test." , pFile ); fseek ( pFile , 9 , SEEK_SET ); fputs ( " new" , pFile ); fclose ( pFile ); return 0; }