RAD Studio |  |

ftell

Header File

stdio.h

Category

Input/output Routines

Prototype

long int ftell(FILE *stream);

Description

Returns the current file pointer.

ftell returns the current file pointer for stream. The offset is measured in bytes from the beginning of the file (if the file is binary). The value returned by ftell can be used in a subsequent call to fseek.

Return Value

ftell returns the current file pointer position on success. It returns -1L on error and sets the global variable errno to a positive value.

In the event of an error return the global variable errno is set to one of the following values:

EBADF | Bad file pointer
ESPIPE | Illegal seek on device

Example

Copy Code

    #include <stdio.h>
    int main(void)
    {
       FILE *stream;
       stream = fopen("MYFILE.TXT", "w+");
       fprintf(stream, "This is a test");
       printf("The file pointer is at byte %ld\n", ftell(stream));
       fclose(stream);
       return 0;
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
+ | + | + | +

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!