A
a
To solve the 100k * 100k data, I finally adopt the file read method and use
malloc. The system somehow knows to use virtual memory.
Now I first test 1k * 1k data but something uninterpretable happens again.
The data file starts with:
42.106983132 85.931514337 98.155213938 23.685776453 76.827067592
....
when I print out the array storing the file content:
0.000000 k: 1020 r: 0.000000 k: 1021 r: 0.000000 k: 1022 r: 0.000000 k: 1023
r: 0.000000 k: 1024 r: 42.106983 k: 1025 r: 85.931514 k:
one can see the first line reading nothing (k as index and r as array
content)
I use the function fscanf to read the file:
#define SIZE 1024
double *r;
int i = 0;
r = (double *)malloc(SIZE * SIZE * sizeof(double));
while(!feof(file) && i<SIZE * SIZE) {
fscanf(file, "%lf", &r);
i++;
// if (i < 30 ) return;
}
for (k=0; k<SIZE*SIZE; k++) {
// if (k> SIZE * SIZE - 10 )
if (k< 2048 )
printf("k: %d r: %lf ",k, r[k]);
}
and indeed if (i < 30) return does not stop the file reading loop and i need
to add i < SIZE * SIZE to stop infinite reading. Anybody knows what's
happening?
Furthermore, when I use scanf, fscanf etc to search in Google, it returns
not so helpful example results. I'd also appreciate your suggestions on
searching help on web. Thanks a lot!!
malloc. The system somehow knows to use virtual memory.
Now I first test 1k * 1k data but something uninterpretable happens again.
The data file starts with:
42.106983132 85.931514337 98.155213938 23.685776453 76.827067592
....
when I print out the array storing the file content:
0.000000 k: 1020 r: 0.000000 k: 1021 r: 0.000000 k: 1022 r: 0.000000 k: 1023
r: 0.000000 k: 1024 r: 42.106983 k: 1025 r: 85.931514 k:
one can see the first line reading nothing (k as index and r as array
content)
I use the function fscanf to read the file:
#define SIZE 1024
double *r;
int i = 0;
r = (double *)malloc(SIZE * SIZE * sizeof(double));
while(!feof(file) && i<SIZE * SIZE) {
fscanf(file, "%lf", &r);
i++;
// if (i < 30 ) return;
}
for (k=0; k<SIZE*SIZE; k++) {
// if (k> SIZE * SIZE - 10 )
if (k< 2048 )
printf("k: %d r: %lf ",k, r[k]);
}
and indeed if (i < 30) return does not stop the file reading loop and i need
to add i < SIZE * SIZE to stop infinite reading. Anybody knows what's
happening?
Furthermore, when I use scanf, fscanf etc to search in Google, it returns
not so helpful example results. I'd also appreciate your suggestions on
searching help on web. Thanks a lot!!