In C language, ftell() returns the current file position of the specified stream relative to the beginning of the file. This function is used to get the total size of the file after moving the file pointer to the end of the file. It returns the current position as a long and the file can contain more than 32767 bytes of data.
This is the syntax of ftell() in C language,
long int ftell(FILE *stream)
This is the parameter used in ftell(),
stream - This is a pointer to a FILE object that identifies
This is an example of ftell() in C.
Suppose we have a file "one.txt" with the following content.
This is demo text! This is demo text! This is demo text!
Now, let’s look at an example.
#include <stdio.h> #include<conio.h> void main () { FILE *f; int len; f = fopen("one.txt", "r"); if(f == NULL) { perror(“Error opening file”); return(-1); } fseek(f, 0, SEEK_END); len = ftell(f); fclose(f); printf("Size of file: %d bytes", len); getch(); }
Size of file: 78 bytes
The above is the detailed content of In C language, the ftell() function is used to obtain the current position of the file pointer. For more information, please follow other related articles on the PHP Chinese website!