Hi!
I am new to C and try to make a program that reads a segment of data from a file and prints it to the screen. When I declare the array that stores the data read from file as float, it works well. But when I declare it as double, the program prints out only zeros. Can anyone explain why? Am I doing something wrong?
I need to store this data with double precision because of computations that will be done with them later. How can I fix it?
Here is the code:
Thank you in advance!Code:# include <stdio.h> int main (void) { FILE *fpIn = fopen( "S001.txt", "r"); // Open input file const int nsize = 2048; double y[200000]; if (fpIn != NULL) // Successful opening of input file { // Reads from input file first segment of nsize samples into y: unsigned int i; int numRead = 0; for (i = 0; i < nsize; i++ ) { numRead = fscanf(fpIn, "%f", &y[i]); printf("%f\n",y[i]); } close(fpIn); // Close input file } return 0; }
Elena