unix高级编程:获取文件长度

来源:互联网 发布:vmware 设置网络 编辑:程序博客网 时间:2024/05/29 07:09
#include <stdio.h>#include <stdlib.h>int main(int argh, char* argv[]) {    char* filename = argv[1];    FILE* file = fopen(filename, "r");    if (file == NULL) {        perror("fopen");        goto fail;    }    fseek(file, 0, SEEK_END);    long file_length = ftell(file);    if (file_length == -1) {        perror("ftell");        goto fail;    }    return EXIT_SUCCESS;fail:    fclose(file);    return EXIT_FAILURE;}
1 0
原创粉丝点击