So I've been having some difficulties storing some numbers from a .dat file. The file is as follows:
1
2
7
10
9
4
0
5
6
8
3
The code I have to try and retrieve this information is:
#include <stdio.h>
#include <stdlib.h>
#define N 11
int main(int argc, char** argv) {
//Declare variables: number of elements, counter, array, & valuesto
//print
int i;
double a[N], num, temp;
FILE* dat;
//Print space for program cleanliness
printf("\n");
//Open file
dat = fopen("zero.dat", "r");
//Initialize i
i=0;
//Read in infromation from file
while(!feof(dat) && i < N){
printf("This is loop number %d\n", i);
num = fscanf(dat,"%lf", &temp);
printf("Temp variable is stored as: %f\n", temp);
printf("Number of characters read in: %d\n\n", num);
a[i] = temp;
i++;
}
fclose(dat);
for(int j=0;j<i;j++){
printf("%f\n", a[j]);
}
//Exit program
exit(EXIT_SUCCESS);
}
/**************************************************************************/
And the output is:
This is loop number 0
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 1
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 2
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 3
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 4
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 5
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 6
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 7
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 8
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 9
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
This is loop number 10
Temp variable is stored as: 0.000000
Number of characters read in: 1541763072
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
Also, it should be noted that I am using NetBeans IDE 8.0.2; and the zero.dat file is located within the same project folder as the source.