fseek - C stdio.h

C examples for stdio.h:fseek

Type

function

From


<cstdio>
<stdio.h>

Description

Reposition stream position indicator

Prototype

int fseek ( FILE * stream, long int offset, int origin );

Parameters

ParameterDescription
stream FILE object.
offset offset
origin Position used as reference for the offset.

origin could be the following:

ConstantReference position
SEEK_SETBeginning of file
SEEK_CURCurrent position of the file pointer
SEEK_END End of file

Return Value

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.

Demo Code


#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;
}

Related Tutorials