ftell
Returns the current read/write position of a stream
#include <stdio.h>
long int ftell (
FILE *fp);
The ftell function returns the current read/write position of the file specified by fp. When an error is detected, a value of -1 is returned. If an error occurs, errno is set.
The ftell function returns the current read/write position of the file specified by fp. This position defines the character to be read or written by the next I/O operation on the file. You can use the value returned by ftell in a subsequent call to fseek in order to set the file to the same position.
You can determine the size of a file by using the following example, which saves and restores the current position of the file.
#include <stdio.h> long int filesize (FILE *fp) { long int save_pos, size_of_file; save_pos = ftell (fp); fseek ( fp, 0L, SEEK_END); size_of_file = ftell (fp); fseek (fp, save_pos, SEEK_SET); return (size_of_file); }