[問題] 用fread讀入binary檔

看板C_and_CPP作者 (寒云)時間11年前 (2012/11/02 23:13), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) C 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 小弟用一個多類別的結構讀入一binary檔案 結構的大小剛好為235bytes binary檔案很大 結構只有需要讀入前235個bytes 然而為了驗證 寫出的檔案確有240個bytes 多出了五個bytes 內容是完全正確的 就連後面多讀的五個也是 可是不應該讀入這麼多 請為各位神人大大這該怎麼解決呢?<(_ _)> 餵入的資料(Input): 200mb的binary檔案 預期的正確結果(Expected Output): 正確大小的結構組 錯誤結果(Wrong Output): 多了5bytes 程式碼(Code):(請善用置底文網頁, 記得排版) 結構為 struct h{ char a[4]; unsigned short b,c,d,e; unsigned long f,g,h,i[5]; double j,k,l,m,n,o,p,q,r,s,t,u; unsigned long long v; }; struct h header; 讀入指令為 FILE *fp=fopen("111.bin","rb"); fread(&h,sizeof(struct h),1,fp); 寫出指令為 fwrite(&h,sizeof(struct h),1,fp); 補充說明(Supplement): -- 領 白◢██◣__ ◢███◣__◢██◣  導 目  白 ████ˍ ⊙ ⊙  目─⊙-⊙- 白██ ███□︵□◥█偶臭了嗎!?◥█你說完了沒? 你這不是見到我了嗎? 種 ◢█ ◢██ ◢█ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.165.181.100

11/02 23:18, , 1F
alignment
11/02 23:18, 1F

11/02 23:22, , 2F
可以印出sizeof(struct h)來看看
11/02 23:22, 2F
※ 編輯: rockkao2001 來自: 118.165.181.100 (11/03 00:36)
文章代碼(AID): #1Ga-C1A8 (C_and_CPP)