Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

fseek
c
file

What is fseek() in C?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The C library function fseek() sets the file position of the stream to a given offset. The pointer associated with the file is moved to that offset.

Syntax

The basic syntax of the function is:

svg viewer

whence defines the point with respect to where the file pointer needs to be moved. It is specified by one of the following constants:

  • SEEK_END: End of the file.
  • SEEK_SET: Beginning of the file.
  • SEEK_CUR: Current position of the file pointer.​

Code

The following code opens a text file and moves the pointer to the end of the file using the SEEK_END argument. It then moves the pointer three places ahead of the start of the file, using the SEEK_SET argument, and prints the remaining characters in the file.

main.c
file.txt
Hello World

RELATED TAGS

fseek
c
file
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring