C语言ftell()函数
作者:--
发布时间:2019-11-20
评论:0
阅读:0
ftell()函数返回指定流的当前文件指针的位置。在文件末尾移动文件指针后,我们可以使用ftell()函数获取文件的总大小。可以使用seek_end常量来将文件指针移动文件末尾。
ftell()函数的语法:
long int ftell(file *stream)
示例:
创建一个源文件:ftell-file.c,其代码如下所示 -
#include <stdio.h>
void main() {
file *fp;
int length;
fp = fopen("myfile.txt", "r");
fseek(fp, 0, seek_end);
length = ftell(fp);
fclose(fp);
printf("size of file: %d bytes", length);
}
执行上面示例代码后,得到以下结果 -
size of file: 15 bytes