Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ftell, ftello, ftell64, ftello64 - Determine current position of read/write pointer

&pagelevel(4)&pagelevel

Definition  

#include <stdio.h>

long ftell(FILE *fp);
off_t ftello(FILE *fp);
long long ftell64(FILE *fp);
off64_t ftello64(FILE *fp);

ftell/ftello and ftell64/ftello64 return the current position of the read/write pointer for the file with file pointer fp.

ftell/ftello and ftell64/ftello64 can be used on binary files (SAM in binary mode, PAM, INCORE) as well as text files (SAM in text mode, ISAM).

To process files > 2 GB, proceed as follows:

  • If the _FILE_OFFSET_BITS 64 define (see "Support for DMS and UFS files > 2 GB") is set, call ftello. ftello64 is then used implicitly with the appropriate parameters.

  • Otherwise, you have to call ftell64 or ftello64.

There is no functional difference between ftell and ftell64 or ftello and ftello64.
The functions differ only in terms of the offset type used for the return value.

Return val.

Position in the file if successful:



for binary files, the number of bytes that offsets the read/write pointer from the beginning of the file, for text files, the absolute position of the read/write pointer.


-1

if an error occurs.
If the value for the file position does not lie within the value range of the return type, errno is additionally set to ERANGE.

Notes

The functions fseek/fseeko and fseek64/fseeko64 can be used to position on the position returned by ftell/ftello and ftell64/ftello64.

ftell/ftello and ftell64/ftello64 cannot be used for system files (SYSDTA, SYSLST, SYSOUT).

Example 

In the following program, each character in file is output with the position of the read/write pointer, starting with the eleventh character (only functions with binary files).

#include <stdio.h>
int main(void)
{
   FILE *fp;
   int c;
   if((fp = fopen("file","rb")) != NULL)
     {
               /* the first 10 characters are skipped */
       fseek(fp,10L,SEEK_SET);
       while((c=getc(fp)) != EOF)
            printf("Position : %ld, character : %c\n",ftell(fp),c);
       fclose(fp);
     }
   return 0;
}

See also

fseek, fseek64, fgetpos, fgetpos64, ftell, ftell64, tell