1. 程式人生 > 實用技巧 >資料檔案——之讀取寫入二進位制檔案的結構

資料檔案——之讀取寫入二進位制檔案的結構

程式碼:

 1 //This is c program code!
 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 3   * 文件資訊: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_14.c
 4   * 版權宣告: *** :(魎魍魅魑)MIT
 5   * 聯絡信箱: *** :[email protected]
 6   * 建立時間: *** :2020年11月21日的下午07:17
 7   * 文件用途: *** :資料結構與演算法分析-c語言描述
 8   * 作者資訊: *** :guochaoxxl(
http://cnblogs.com/guochaoxxl) 9 * 修訂時間: *** :2020年第46周 11月21日 星期六 下午07:17 (第326天) 10 * 檔案描述: *** :自行新增 11 * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/ 12 #include <stdio.h> 13 #include "closeState.h" 14 15 int main(int argc, char **argv) 16 { 17 Bio bio;
18 FILE *fPtr = fopen("agentsb.dat", "rb"); 19 if(fPtr != NULL){ 20 printf("File agentsb.dat is opened successfully.\n"); 21 int ch = fread(&bio, sizeof(bio), 1, fPtr); 22 while(ch != 0){ 23 printf("Name: %s, RollNo: %d, Age: %d, Weight: %.1f\n", bio.name, bio.rollNo , bio.age, bio.weight);
24 ch = fread(&bio, sizeof(bio), 1, fPtr); 25 } 26 int clo; 27 closeState(clo, fPtr); 28 }else{ 29 puts("File-opening failed."); 30 } 31 32 return 0; 33 }