C语言学习笔记之获取文件长度

2018-08-02  本文已影响0人  Metaphors

本文为原创文章,转载请标明出处

#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *inputFile;
    inputFile = fopen("data.bin", "rb");
    if (!inputFile) {
        fprintf(stderr, "Can't open bin file!");
        exit(1);
    }

    fseek(inputFile, 0, SEEK_END);
    long inputFileLength = ftell(inputFile);
    printf("input file length: %ld\n", inputFileLength);
    fseek(inputFile, 0, SEEK_SET);

    fclose(inputFile);
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读