I now see a way that it can seg-fault. It can happen if the program fails to open the output file.
So, first thing I would do is add a null check before trying to printf into it.
I now see a way that it can seg-fault. It can happen if the program fails to open the output file.
So, first thing I would do is add a null check before trying to printf into it.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Calculation should use cast:
x = (double)i/steps;
Otherwise dividing an int with an int will not get desired result.
Ha! it was all those for loops below. i had:
Should have been:Code:for(i=0; i++; i<10)
Stupid mistakes!Code:for(i=0; i<10; i++)
A problem I see :
your integral_yn has 10 members, 0 - 9. Your for loop uses indexes 1 - 10.Code:#define MAX_N 10 double integral_yn[MAX_N] for(n=1; n<10; n++) { .... integral_yn[n] = 0; }
Actually he's only using 9 of the 10 since he's starting at 1 ....
Follow that loop around a few times...
n = 1 ... n is < 10 ... assign value
n = n + 1
n = 2 ... n is < 10 ... assign value
...
n = 9 ... n is < 10 ... assign value
n = n + 1
n = 10 ... n is not < 10 ... exit loop