一次讀入整個二進位制檔案

2021-08-25 21:27:40 字數 448 閱讀 6187

1.開啟檔案

if((fp = fopen(file_name, "rb+")) == null)

2.得到檔案的長度

fseek(ap->fp, 0l, seek_end);

file_size = ftell(fp);

if(-1l == file_size)

3.建立等大小的緩衝

char *buffer = (char *)malloc(file_size);

if (null == buffer)

4.讀入檔案

rewind(fp)

if((count_tmp=fread(buffer, sizeof(char), file_size, fp)) != file_size)

5.從buffer中解析出資料

在比如讀入資料初始化程式且資料量不大的地方,一次性讀入檔案是速度比較快的選擇

一次讀入整個二進位制檔案

1.開啟檔案 if fp fopen file name,rb null 2.得到檔案的長度 fseek ap fp,0l,seek end file size ftell fp if 1l file size 3.建立等大小的緩衝 char buffer char malloc file size...

檔案操作 二進位制檔案讀入

time limit 1 sec memory limit 128 mb submit 88 solved 24 submit status web board 現有100名學生的姓名 name 學號 num 英語 english 數學 math 語文 chinese 成績儲存在乙個二進位制檔案st...

Problem A 檔案操作 二進位制檔案讀入

time limit 1 sec memory limit 128 mb submit 1952 solved 524 submit status web board 現有100名學生的姓名 name 學號 num 英語 english 數學 math 語文 chinese 成績儲存在乙個二進位制檔...