码迷,mamicode.com
首页 > 编程语言 > 详细

C语言计算文件大小

时间:2021-06-05 17:44:27      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:pes   har   语言   bytes   get   amp   函数   unsigned   class   

通过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语言计算文件大小

标签:pes   har   语言   bytes   get   amp   函数   unsigned   class   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!