ftell() in C with example
ftell() in C is used to find out the position of file pointer in the file with respect to starting of the file. Syntax of ftell() is:
long ftell(FILE *pointer)
Consider below C program. The file taken in the example contains the following data :
“Someone over there is calling you. We are going for work. Take care of yourself.” (without the quotes)
When the fscanf statement is executed word “Someone” is stored in string and the pointer is moved beyond “Someone”. Therefore ftell(fp) returns 7 as length of “someone” is 6.
// C program to demonstrate use of ftel() #include<stdio.h> int main() { /* Opening file in read mode */ FILE *fp = fopen("test.txt","r"); /* Reading first string */ char string[20]; fscanf(fp,"%s",string); /* Printing position of file pointer */ printf("%ld", ftell(fp)); return 0; } |
Output : Assuming test.txt contains “Someone over there ….”.
7
This article is contributed by Hardik Gaur. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- asctime() and asctime_s() functions in C with Examples
- time.h header file in C with Examples
- __builtin_inf() functions of GCC compiler
- Count substrings that contain all vowels | SET 2
- How can we use Comma operator in place of curly braces?
- Basic Code Optimizations in C
- Constants vs Variables in C language
- Sum of an array using MPI
- Difference between pointer to an array and array of pointers
- dot (.) operator in C/C++
- Features and Use of Pointers in C/C++
- Difference between while and do-while loop in C, C++, Java
- C program to sort an array using pointers
- C Program to count the Number of Characters in a File



