long ftell ( FILE * stream );
Return the current position in a stream.
Returns the current position pointed by the position indicator of the stream. When a file has been opened in binary mode the value obtained corresponds to the number of bytes from the beginning of the file. In files opened in text-mode this is not granted because of carriage-return translations under that mode. The value returned is valid for further calls to fseek.
On success, the current file pointer position is returned.
If an error occurs -1L is returned and the global variable errno is set to a positive value.
If the stream is unable to perform seeking operations (like modems) the return value is undefined.
Defined in ANSI-C.
/* ftell example : getting size of a file */
FILE * pFile;
pFile = fopen ("myfile.txt","rb");
if (pFile==NULL) perror ("Error opening file");
fseek (pFile, 0, SEEK_END);
printf ("Size of myfile.txt: %ld bytes.\n",size);
This program opens example.txt for reading and calculates its size.
Size of example.txt: 735 bytes
fopen, fseek, fgetpos