ftell function

Prototype long int ftell (FILE * Stream);
PurposeTo get the location of a file pointer.
Header File#include <stdio.h>
Parameters
StreamPointer to an open FILE
Return Value
>= 0Success
-1LFailure
Side Effects
errnoSet on failure to:
EBADFBad file pointer
ESPIPEIllegal seek on device
  • These error number constants and the variable errno are defined in errno.h.
Notes
  • File pointer position returned is bytes from the beginning of the file.
Example #include <stdio.h> #include <errno.h> . . . FILE * Account_Master; long int File_Size; . . . if (fseek (Account_Master, 0, SEEK_END) == 0) { File_Size = ftell (Account_Master); if (File_Size >= 0) printf ("File is %i bytes long.", File_Size); else printf ("Function ftell failed with error %i.", errno); } else { printf ("Seek failed."); }
Related functions
fopen fclose fread fwrite fseek rewind

c/c++ Index