C中的ftell()
用C语言ftell()返回相对于文件开头的指定流的当前文件位置。在文件末尾移动文件指针后,此函数用于获取文件的总大小。它以long类型返回当前位置,并且文件可以包含32767字节以上的数据。
这是ftell()C语言的语法,
long int ftell(FILE *stream)
这是在中使用的参数ftell(),
stream-这是指向标识流的FILE对象的指针。
这是ftell()C语言的示例。
假设我们有一个包含以下内容的文件“one.txt”。
This is demo text! This is demo text! This is demo text!
现在,让我们来看一个例子。
示例
#include <stdio.h>
#include<conio.h>
void main () {
FILE *f;
int len;
f = fopen("one.txt", "r");
if(f == NULL) {
perror(“Error opening file”);
return(-1);
}
fseek(f, 0, SEEK_END);
len = ftell(f);
fclose(f);
printf("Size of file: %d bytes", len);
getch();
}输出结果
Size of file: 78 bytes
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬