Function ftell () in C
The function long int ftell (FILE * stream) in standard C Library returns the current file location of the given Stream.
The function long int ftell (FILE * stream) in standard C Library returns the current file location of the given Stream.
Declare ftell () function in C
Below is the declaration for ftell () function in C:
long int ftell ( FILE * stream )
Parameters
stream - This is the pointer to a FILE object that identifies the Stream.
Returns the value
This function returns the current value of position indicator. If an error occurs, -1 is returned, and the global variable errno is set to a positive value.
For example
The following program C illustrates the usage of the ftell () function in C:
#include int main () { FILE * fp ; int len ; fp = fopen ( "baitapc.txt" , "r" ); if ( fp == NULL ) { perror ( "Xay ra loi khi mo file!!!" ); return (- 1 ); } fseek ( fp , 0 , SEEK_END ); len = ftell ( fp ); fclose ( fp ); printf ( "Tong kich co cua baitapc.txt = %d bytesn" , len ); return ( 0 ); }
Suppose we have the bait.txt file with the following content:
Hoc C co ban va nang cao tai QTM !!!
Compiling and executing the above program will produce the following result if the file has the above content, otherwise it will give different results depending on the content of the file.
According to Tutorialspoint
Previous post: Function fsetpos () in C
Next lesson: Function fwrite () in C
You should read it
Maybe you are interested
The whole scene of meteorites hitting the Earth during the past 33 years, why can't we feel it? Discovered mysterious signals emanating from a star right next to the Solar System, possibly of aliens NASA reveals its latest snapshot of the Martian surface with a resolution of 1.8 billion pixels Found the second planet of Proxima Centauri, the star closest to the sun 7 most modern astronaut ships on the planet Is Proxima b our 'neighbor' planet?