Function name : tell
Header file : <io.h>
Function prototype : int tell(int handle);
Function : Get the pointer position of the open file
Parameter : int handle is the file handle to obtain the file pointer
Return value : Returns the position of the file pointer of the given file on success, -1 on failure.
Program example : Create a file with the content I like www.dotcpp.com very much!
//Open the file, move seven bytes, and get the current pointer position #include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){intfd=open(D:\a .txt,O_RDONLY);if(fd==-1){printf(cannotopenthefilen);return1;}intpos=tell(fd);printf(beforelseekfunction,currentposition:%ldn,pos);lseek(fd, 7,SEEK_SET);//Move to a position 7 bytes offset from the beginning of the file pos=tell(fd);printf(afterlseekfunction,currentposition:%ldn,pos);close(fd);return0;}
Running results
beforelseekfunction,currentposition:0afterlseekfunction,currentposition:7