首页 > 编程语言 > 详细

C语言计算文件大小

时间:2021-06-05 01:23:48      阅读:24      评论:0      收藏:0      [点我收藏+]
通过stat函数获取文件的大小,单位bytes;无需将文件读入内存,可以计算大文件;
 
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>

int stat(const char *pathname, struct stat *buf);


int main(int argc,char **argv)
{
    struct stat statbuf;

    if(stat(argv[1], &statbuf))
    {
        printf("get file(%s) stat fail.\n",argv[1]);
    }
    printf("input file path is = %s\n", argv[1]);
    printf("file size is %llu bytes\n",(unsigned long long int)statbuf.st_size);
    return 0;
}

 

C语言计算文件大小

原文:https://www.cnblogs.com/grooovvve/p/14851459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!