Format
#include <io.h> long _tell(int handle);
Language Level: Extension
_tell gets the current position of the file
pointer associated with handle. The position is the
number of bytes from the beginning of the file.
Return Value
_tell returns the current position. A
return value of -1L indicates an error, and errno is set to one
of the following values:
| Value | Meaning |
| EBADF | The file handle is not valid. |
| EOS2ERR | The call to the operating system was not successful. |
On devices incapable of seeking (such as screens and printers), the return value is -1L.
Example
This example opens the file tell.dat. It
then calls _tell to get the current position of the file pointer
and report whether the operation is successful. The program then
closes tell.dat.
#include <io.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h>
#define FILENAME "tell.dat"
int main(void)
{
long filePtrPos;
int fh;
printf("Creating file.\n");
system("echo Sample Program > " FILENAME);
if (-1 == (fh = open(FILENAME, O_RDWR|O_APPEND))) {
perror("Unable to open " FILENAME);
remove(FILENAME);
return EXIT_FAILURE;
}
/* Get the current file pointer position. */
if (-1 == (filePtrPos = _tell(fh))) {
perror("Unable to tell");
close(fh);
remove(FILENAME);
return EXIT_FAILURE;
}
printf("File pointer is at position %d.\n", filePtrPos);
close(fh);
remove(FILENAME);
return 0;
/*******************************************************
The output should be:
Creating file.
File pointer is at position 0.
*******************************************************/
}
![]()
fseek -- Reposition File
Position
ftell -- Get
Current Position
lseek -- Move
File Pointer
<io.h>