i have a really big array of numbers with double precision...i tried to write it into a file using fprintf()...i need to write these numbers one in each line so i have done something like this.
if((fp2 = fopen("temp", "w")) == NULL) { perror("File cannot be opened"); exit(1); }
for(int k = 0; k < j; k++ )
{
fprintf(fp2, "%0.3lf\n", diff[k]);
}
However, there is a problem that it writes the data upto certain number of lines after which i gives all zeroes. for example
3.040
0.700
-2.740
0.000
0.000
0.000
0.000
0.000
0.000
i really can't understand what could be the problem. why does it write all values as 0.000 when there are values in the array.
here is how diff was implemented if it helps.
diff = (double *)malloc(fileSize);
diff[0] = data[0];
for(j = 1; j < n; j++ )
{
diff[j] = data[j] - data[j-1];
}
the values from a file were stored in data[]. i then calculated the difference of adjacent values in data[] into diff[] and write it back into another file. fileSize was the size of the original file. and i know for sure that all the values in diff[] are populated correctly.