Name
tell - Gets the current position of the file pointer.
Syntax
#include <io.h>
long tell(handle)
int handle;
Description
The tell function gets the current position of the file
pointer (if any) associated with handle. The position is
expressed as the number of bytes from the beginning of the
file.
Return Value
A return value of -1L indicates an error, and errno is set
to EBADF to indicate an invalid file-handle argument. On
devices incapable of seeking, the return value is undefined.
See Also
ftell(DOS), lseek(DOS)
Example
#include <io.h> #include <stdio.h> #include <fcntl.h>
int fh; long position; main() {
fh = open("data",O_RDONLY);
/* Position = 0 */
position = tell(fh);
printf("position = %ld\n", position);
lseek(fh, -3L, SEEK_END);
/* Position = file length -3 */
position = tell(fh);
printf("position = %ld\n", position);
/* Put pointer back to previous position */
lseek(fh, position, SEEK_SET); }
This program uses tell to find the beginning and a position
three bytes from the end of the file named data.
(printed 6/18/89)