Christof points out problems with atoi() and line endings -- I ran into
similar problems some time ago and resorted to sscanf()-ing what I read
from the file to format it it 'properly' in memory before doing the
conversion.
brad
On Mon, Aug 15, 2022 at 3:39 AM Christof Ressi
wrote:
> Edwin
Edwin has already pointed out the immediate error in your code.
However, there are a lot more problems. First some general issues:
* you need to free the line buffer before returning from the function,
otherwise there will be a memory leak.
* AFAICT, the string buffer passed to atoi() is not
pow() must be giving you 9.999 (or something similar) instead of 10 which
is rounded down to 9 by the int typecast.
This results in 3 * 9 + 2 = 29.
To solve this you can, for example, do a round() before the typecast or you can
add 0.5 to the output of pow() before doing the typecast.
Hi Chris, Brad, All,
I managed to trace the error to the function below. It reads a text file
and copies its contents to a matrix. The file it's reading is always made
of lines with the same number of elements like this below:
0 4 4 8 32
1 4 4 8 32
2 4 4 8 32
...
The specific error I'm getting