//头文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//定义获取文件大小的函数
int Get_File_Size()
{
//打开一个文本文件
FILE *fp = fopen("C:\\Users\\Administrator\\Desktop\\hello.txt", "r");
//判断是否打开成功
if (!fp)
{
//如果打开失败则返回fopen的错误内容
perror("fopen error");
//结束函数
return -1;
}
//fseek函数 fp指针到文件末尾,向前偏移0个字节
fseek(fp, 0, SEEK_END);
//ftell返回文件的大小
int ret = ftell(fp);
//打印文件的大小
printf("文件大小为:%d字节\n", ret);
}
//主函数
int main()
{
//调用获取文件大小的函数
Get_File_Size();
//程序暂停
system("pause");
//程序正常退出
return 0;
}
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有