1、
#include <stdio.h> int main(void) { FILE *fp; double a[10] = {1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1,0.1}; int i; for(i = 0; i < 10; i++) { printf("a[%d] = %f. ", i, a[i]); } //利用fwrite函数将数组的值导出到tmp.bin二进制文件中 if((fp = fopen("tmp.bin", "wb")) == NULL) printf("aFile open failed. "); else { fwrite(a, sizeof(double), 10, fp); fclose(fp); } //利用fread函数读取二进制we年tem.bin的值,保存至数组b中,然后进行显示。 double b[10]; if((fp = fopen("tmp.bin", "rb")) == NULL) printf("aFile open failed. "); else { fread(b, sizeof(double), 10, fp); for(i = 0; i < 10; i++) { printf("elements from array b: b[%d] = %.2f. ", i, b[i]); } fclose(fp); } return 0; }