Syntax
#include <io.h> long _tell(int handle);Description
Value
On devices incapable of seeking (such as screens and printers), the return value is -1L.
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. ****************************************************************************/ }Related Information