Facebook Page Twitter Page LinkedIn Page
× C Standard Library

The C <stdio.h> SEEK_SET, SEEK_CUR, SEEK_END macros is used to set origin, which is the position to which offset is added in the fseek() function.

SEEK_SETBeginning of file
SEEK_CURCurrent position of the file pointer
SEEK_ENDEnd of file *


In the below example, a file is created using fopen() function. The initial content of the file is written to the file using fputs() function. Then, by using fseek() function current file position indicator is set to 10 bytes measured from beginning of the file. After that, agian by using fputs() function, the content of the file is modified.

#include <stdio.h>
int main (){

  FILE *pFile = fopen("test.txt", "wb");

  //writes content in the file
  fputs("This is a test file.", pFile);

  //set the current file position indicator to
  //10 bytes measured from beginning of the file
  fseek(pFile, 10, SEEK_SET);
  //modify the content after 10 bytes
  fputs("modified content.", pFile);

  //close the file

  return 0;

After the code is successfully executed, the test.txt file will contain:

This is a modified content.

❮ C <stdio.h> Library