int fseek ( FILE * stream , long offset , int origin );
Reposition stream's position indicator.
Sets the position indicator associated with the stream to a new position defined by an offset from the location given by the origin parameter.
The End-Of-File indicator of this stream is cleared after a call to fseek.
When using fseek on files opened in text mode consider that you can only be sure of the results if an offset of 0 or an offset equal to a value returned from ftell is specified, any other offset value makes result unpredictable because of Carriage-Return translations under this mode.
The next operation with the stream after a call to fseek can be either for input or output.
|SEEK_SET||(0)||Beginning of file.|
|SEEK_CUR||(1)||Current position of the file pointer.|
|SEEK_END||(2)||End of file.|
If successful the function returns 0. Otherwise it returns nonzero.
Defined in ANSI-C.
/* fseek example */
FILE * pFile;
pFile = fopen ("myfile.txt","w");
fputs ("This is an apple.",pFile);
fputs (" sam",pFile);
After this code is executed, a file called example.txt will
be created and will contain the sentence
This is a sample.
fopen, fsetpos, ftell, frewind