long int ftell ( FILE * stream );
Get current position in stream
Returns the current value of the position indicator of the stream.
For binary streams, this is the number of bytes from the beginning of the file.
For text streams, the numerical value may not be meaningful but can still be used to restore the position to the same position later using fseek (if there are characters put back using ungetc still pending of being read, the behavior is undefined).
- Pointer to a FILE object that identifies the stream.
On success, the current value of the position indicator is returned.
On failure, -1L is returned, and errno is set to a system-specific positive value.
/* ftell example : getting size of a file */
int main ()
FILE * pFile;
pFile = fopen ("myfile.txt","rb");
if (pFile==NULL) perror ("Error opening file");
fseek (pFile, 0, SEEK_END); // non-portable
printf ("Size of myfile.txt: %ld bytes.\n",size);
This program prints out the size of myfile.txt in bytes (where supported).
- Reposition stream position indicator (function)
- Get current position in stream (function)
- Set position of stream to the beginning (function)