VOOZH about

URL: https://www.geeksforgeeks.org/techtips/ftell-c-example/

⇱ ftell() in C with example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ftell() in C with example

Last Updated : 2 Aug, 2025

In C, ftell() is used to determine the position of the file pointer in the file from the beginning of the file.

Syntax of fseek()

The ftell() function is declared in the <stdio.h> header file.

Parameters

  • stream: It is the pointer to the file stream.

Return Value

  • Upon successful execution, It returns a long integer value which represents the current file position (in bytes) from the beginning of the file.
  • It returns -1 if an error occurs.

C Program Demonstrating The Use of ftell() Function.

Suppose the file g4g.txt contains the following data:

g4g.txt

Someone over there is calling you. We are going for work. Take care of yourself.

Output

7

Explanation

In the above program the fscanf() function reads the first word from the file ('Someone') and the pointer moves forward. As the length of "someone" is 7 and the character indices are from 0 to 6. ftell(fp) returns 7.

Comment
Article Tags:
Article Tags: