函数名:tell
头文件:<io.h>
函数原型: int tell(int handle);
功能:获取打开文件的指针位置
参数:int handle 为要获取文件指针的文件句柄
返回值: 成功 返回给定文件的文件指针的位置 ,失败 返回-1
程序例:创建文件,内容为I like www.dotcpp.com very much!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | //打开文件,移动七个字节,获取当前指针位置 #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; } |
运行结果
1 2 | before lseek function,current position: 0 after lseek function,current position: 7 |
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程