Must I dynamically allocate memory to variables that are to be user determined at run-time? For instance, I have this code...
On running the whole project, [ctrl+F5], it crashes, even tho' it comiples without errors. On debugging, I found that the user-defined variable x, initialized to 0 at run-time, becomes this bogus number:
-9.2559631349318e+061, which i certainly didn't put in!! the array, s[t] behaves in an equally unlikey manner:
-->s[0] = 1.0000//fine! initialized so.
-->s[1] = 6.2831853071796//also fine:2*1*PI
-->s[2] = -9.2559631349318e+061//huh?!!!!!!!!!!
I'd appreciate any tips on this...thanks a lot!
Code:
void unbound(double *unbd, int nSize)
{
enum{nSize = 100};
double A[nSize],B[nSize],k0[nSize],k1[nSize],s[nSize],expi[nSize],a[nSize],b[nSize];
void bessk0(double *x,double *k0,int nSize);
void bessk1(double *x,double *k1, int nSize);
void ei(double *x, double *expi, int nSize);
double x = 0;
//trial: K0(x) --> x = rw*sqrt(s), as per A-32
s[0] = 1;
for (int t=1;t<nSize;t++)
{
CKuchukDlg MyClas;
MyClas.m_dWellRad = x;//do i set this dynamically? how??
s[t] = 2*t*PI;
a[t] = x*sqrt(s[t]);
b[t] = 2*sqrt(s[t]);
bessk0(a,k0,nSize);
bessk1(a,k1,nSize);
ei(b,expi,nSize);
A[t] = k0[t]/(x*sqrt(s[t])*k1[t]);
B[t] = (1-exp(-2*sqrt(s[t])))/(2*sqrt(s[t]));
unbd[t]=0.5*(A[t]-B[t]-expi[t]);
}
}
-9.2559631349318e+061, which i certainly didn't put in!! the array, s[t] behaves in an equally unlikey manner:
-->s[0] = 1.0000//fine! initialized so.
-->s[1] = 6.2831853071796//also fine:2*1*PI
-->s[2] = -9.2559631349318e+061//huh?!!!!!!!!!!
I'd appreciate any tips on this...thanks a lot!