Skip to content

Instantly share code, notes, and snippets.

@Mhacom
Created May 25, 2014 06:21
#include <stdio.h>
#include <math.h>
#define MAX 30
int main(void)
{
setbuf(stdout,NULL);
char *fileName = "myArray.txt";
double a[MAX] ;
int i;
for(i = 0 ; i < MAX ;i++)
{
a[i] = sqrt(i);
}
FILE *fout = fopen(fileName,"wb");
if(fout == NULL) exit(-1);
fwrite(a,sizeof(double) ,MAX , fout);
fclose(fout);
FILE *fin = fopen(fileName,"rb");
if(fin == NULL) exit(-1);
double b[MAX];
fread( b, sizeof(double), MAX , fin );
for(i = 0 ; i < MAX ;i++)
{
printf("%d : %f\n",i,b[i]);
}
fclose(fin);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment