函数名:tell
头文件:<io.h>
函数原型: int tell(int handle);
功能:获取打开文件的指针位置
参数:int handle 为要获取文件指针的文件句柄
返回值: 成功 返回给定文件的文件指针的位置 ,失败 返回-1
程序例:创建文件,内容为I like www.dotcpp.com very much!
//打开文件,移动七个字节,获取当前指针位置 #include<stdio.h> #include<io.h> #include<fcntl.h> int main(void){ int fd=open("D:\\a.txt",O_RDONLY); if(fd==-1){ printf("can not open the file\n"); return 1; } int pos=tell(fd); printf("before lseek function,current position: %ld\n",pos); lseek(fd,7,SEEK_SET); //移动到以文件的开头偏移7个字节的位置 pos=tell(fd); printf("after lseek function,current position: %ld\n",pos); close(fd); return 0; }
运行结果
before lseek function,current position: 0 after lseek function,current position: 7
本文固定URL:https://www.dotcpp.com/course/462