C语言读取文件大小 - 示例代码
以下是用 C 语言实现读取文件长度的示例代码:
#include <stdio.h>
int main() {
FILE *file;
long length;
// 打开文件
file = fopen('filename.txt', 'r');
if (file == NULL) {
printf("无法打开文件\n");
return 1;
}
// 移动文件指针到文件末尾
fseek(file, 0, SEEK_END);
// 获取文件长度
length = ftell(file);
// 关闭文件
fclose(file);
printf("文件长度为 %ld 字节\n", length);
return 0;
}
请将代码中的 'filename.txt' 替换为你要读取的文件的路径和名称。
原文地址: https://www.cveoy.top/t/topic/qC33 著作权归作者所有。请勿转载和采集!