However when I print the array I get weird values. If I substitute the array variable with a regular double variable and inside the previously mentioned while loop print the value of this variable it gets printed correctly. What is wrong with the mentioned code? I tried initializing all values in the array beforehand, but, of course, that was no help either.

First of all you have to add a condition so i doesn't get to high and overwrites memory outside of the array. Second, did you print i and arr[i] inside the loop as well?
–
Joachim PileborgNov 5 '11 at 7:08

What you posted should work. I think you're not showing us the real code, but a "simplified" version.
–
cnicutarNov 5 '11 at 7:08

What he posted should not work; if there are non-double values in file, it would be an infinite loop
–
user411313Nov 5 '11 at 8:43

1

@user411313 The man page for fscanf() says: "... EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs..."
–
alkNov 5 '11 at 11:24

Can you post the file and the results you get?
–
BlackBearNov 5 '11 at 12:25

1 Answer
1

You may want to parenthesis around the array. For example, in the code, you have "&arr[i]". This is the same as (&arr)[i] which means get the address of the array pointer (a pointer to a pointer) with an offset of i. This could offset the writings by a few bits, which makes the output seem funky.