获得文件大小

来源:互联网 发布:psd下载软件 编辑:程序博客网 时间:2024/04/29 00:12

  int fseek(FILE *stream, long offset, int whence);

  long ftell(FILE *stream);

先将文件按定位到末尾,然后ftell函数返回当前读写位置


#include <stdio.h>int main(int argc, char** argv){    if (argc < 2)    {        printf("please input the file name.\n");    }FILE* fp = fopen(argv[1], "r");if ( NULL == fp){        printf("file open error")    return 0;}    if ( fseek(fp, 0, SEEK_SET) == -1){printf("fseek error!");}if ( fseek(fp, 0, SEEK_END) == -1){printf("fseek error!");}long size = ftell(fp);printf("athe file size %ld\n", size);return 0;}

原创粉丝点击