C語言學習筆記之獲取文件長度

本文爲原創文章,轉載請標明出處html

#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;
}
相關文章
相關標籤/搜索