fseek()

The fseek() function is used for setting the file pointer at the specific position in the file. Here is its syntax:

fseek(FILE *file_pointer, long int offset, int location);

This function has the following features:

Value Meaning
0 The file pointer will be moved from the beginning of the file
1 The file pointer will be moved from the current position
2 The file pointer will be moved from the end of the file

 

Let's look at the following example. Here, the file pointer will be moved 5 bytes forward from the beginning of the file:

fseek(fp,5L,0)

In the following example, the file pointer will be moved 5 bytes backward from the end of the file:

fseek(fp,-5L,2)