Relatively straightforward question: When you call elements in an array, say data[i][j], where elements have been defined from i,j=0 to some higher (integer) number.
Is it possible to use a command when calling array elements, so that if somehow in data[i][j] "i" ended up being less than zero, it would instead call the value stored in the corresponding positive value of i?
For example, with an array called data, calling the element data[-1][0], in this case it would call data[1][0].
I tried adding abs() commands to array calls,such as data[abs(i)][0] but that just caused the compiler to crash (In case I needed to make it clear that I have no idea what I'm doing).
I'm fairly sure the code is calling values of negative [i] elements in the array after a the first loop (I would expect it to), and it's making the compiler crash.
A little bit of what my code is, in case anyone feels its important. It could probably be a lot more intuitive somehow, but I'm not worried about that, as long as it works.
Ignore any variables that aren't defined in the above snippet, they were earlier.Code:double **data; data=(double**)malloc(nradius*sizeof(double*)); //dynamically allocate memory for the array "data". int i; for(i=0; i<nradius; i++) { data[i]=(double*) malloc(ntime*sizeof(double)); } //initialise the array for(i=0; i<nradius; i++) { data[i][0]=1+sin(k*r); r=r+deltar; } //horrible differential equation loop that isn't relevant to southperry goes here
I suppose I could shift everything definitions up by an arbitrary number, but it would require a lot of unintuitive redefinitions that I would rather avoid if there it is possible to just redirect the error causing array elements.
Bookmarks