zl程序教程

您现在的位置是:首页 >  其他

当前栏目

数据文件——之读取写入二进制文件的整数

文件二进制 读取 写入 整数 数据文件
2023-09-11 14:22:20 时间

代码:

 1 //This is c program code!                                                               
 2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test7_13.c
 4   * 版权声明: *** :(魎魍魅魑)MIT
 5   * 联络信箱: *** :guochaoxxl@163.com
 6   * 创建时间: *** :2020年11月21日的下午06:48
 7   * 文档用途: *** :数据结构与算法分析-c语言描述
 8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
 9   * 修订时间: *** :2020年第46周 11月21日 星期六 下午06:48 (第326天)
10   * 文件描述: *** :自行添加
11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
12 #include <stdio.h>
13 #include "closeState.h"
14 
15 #define SIZE 10
16     
17 int main(int argc, char **argv)
18 {   
19     int arrNum[SIZE];
20     FILE *fPtr = fopen("num.dat", "rb");
21     if(fPtr != NULL){
22         puts("File num.dat is opened successfully.");
23         fread(arrNum, sizeof(int), SIZE, fPtr);
24         puts("Contents of file num.dat: ");
25     
26         for(int i = 0; i < 10; i++){
27             printf("%d\t", arrNum[i]);
28         }
29         printf("\n");
30     
31         int clo;
32         closeState(clo, fPtr);
33     }else{
34         puts("File-opening failed!");
35     }
36     
37     return 0;
38 }