#include <stdio.h>
#include <string.h>
#include <stdlib.h>// argc = argv指针数组长度+1
int main(int argc,const char *argv[])
{// 如果没给文件路径的话报错if(argc != 2) {printf("参数无效!\n");exit(-1);}// 打开文件,用只读方式打开,光标在首个地址FILE *file = fopen(argv[1],"a");// 错误处理if(!file){perror("文件打开出错");exit(-1);}// ftell计算文件偏移量long count = ftell(file);printf("文件的大小是: %ldbytes\n", count * sizeof(char));// 关闭文件,释放堆内存fclose(file);
}