C examples for stdio.h:ftell
function
<cstdio> <stdio.h>
Get current position in stream
long int ftell ( FILE * stream );
Parameter | Description |
---|---|
stream | FILE object |
On success, the current position is returned.
On failure, -1L is returned, and errno is set to a system-specific positive value.
This program prints out the size of main.cpp in bytes.
#include <stdio.h> int main ()/*from ww w . j a v a2 s . co m*/ { FILE * pFile; long size; pFile = fopen ("main.cpp","rb"); if (pFile==NULL){ perror ("Error opening file"); return -1; } fseek (pFile, 0, SEEK_END); // non-portable size=ftell (pFile); fclose (pFile); printf ("Size of main.cpp: %ld bytes.\n",size); return 0; }