chap06/mkbin.c
1/* -*- C -*- */
2#include <stdio.h>
3
4int main()
5{
6 const int N = 10;
7
8 int i;
9 double x[N];
10 FILE *fp;
11
12 // open
13 fp = fopen("cbinary.dat", "w");
14
15 if( fp == NULL ) {
16 printf("Failed to open file\n");
17 return -1;
18 }
19
20 // write data
21 for(int i=0; i < N; i++) {
22 x[i] = i * 0.5 + 1.0;
23 }
24
25 fwrite(x, sizeof(double), N, fp);
26
27 // close
28 fclose(fp);
29
30 return 0;
31}
32