# Thread: for loop and array problem

1. ## for loop and array problem

i use this for loop a lot in the programm

Code:
```void op(int n,int m,int ir,int du,int dl,int nm1,double w[9801],double b[9801],double g[9801])

{
double sum;
int T1,l,j,nmr,ndl,ndu;
nmr = n-m+ir;
ndl = n-dl;
ndu = n-du-1;
sum = 0;
..........

for(l=0;l<=nmr-j;l++)
{
T1 = j+m-ir+l;
if(ir-l>0)
{
464	         pq(n,dl,i,T1,v,y);
465	         sum = sum+e[ir-l-1][j+1-ir+l-1]*am[v-1][y-1];
}
}```
Code:
```void pq(int n,int dl,int p,int q,int v,int y)
{

if(p >= q)
{
v = n+1-p;
y = p+1-q;
}
else
{
v = n+1-q;
y = dl+q-p;
}

}```
and get this errors

C:\Documents and Settings\massimo!\Desktop\test.c(464) : warning C4047: 'function' : 'int ' differs in levels of indirection from 'double [9801]'
C:\Documents and Settings\massimo!\Desktop\test.c(464) : warning C4024: 'pqtest' : different types for formal and actual parameter 5
C:\Documents and Settings\massimo!\Desktop\test.c(464) : warning C4047: 'function' : 'int ' differs in levels of indirection from 'double [9801]'
C:\Documents and Settings\massimo!\Desktop\test.c(464) : warning C4024: 'pqtest' : different types for formal and actual parameter 6
C:\Documents and Settings\massimo!\Desktop\test.c(465) : error C2107: illegal index, indirection not allowed
C:\Documents and Settings\massimo!\Desktop\test.c(465) : error C2107: illegal index, indirection not allowed
C:\Documents and Settings\massimo!\Desktop\test.c(465) : error C2297: '*' : illegal, right operand has type 'double (*)[800]'

i dont understand,if you please have an idea

2. I don't see any declaration of an e or am array (or variables i, v, and y for that matter) in the op function, and your variable names could use some work.

Furthermore, your call to the pq function does nothing. Although you modify v and y within the function, since you've passed the arguments by value/copy, only the value of the variables within the pq function have any meaning and once the function exits, those values are lost.[/edit]

3. Too many parameters is making this function hard to read, and even then you're still using global variables!

Whatever you're doing is quite messy, but it appears your errors might have to do with your global variables unless someone spots something I missed.

4. e and am arrays are global variables..just look the variables that being used in this for loop.

5. If I were your instructor, I would fail you with this code, whether it worked or not.

Todd

6. i didn't put the whole code,just the part i thought that is needed.sorry if i am mistaken....

7. What types are your global arrays?

8. The compiler is complaining about arguments five and six ("v" and "y", which must be global variables since they aren't defined here); it seems to think that these are 9801-element arrays of double, but the function is expecting int.

I'm with hk; real variable names would have kept you out of this mess, I think.

9. Get rid of the global variables, put them in op (or wherever you want them), show us the code with ALL the variables, and rename them to reasonable names. THEN show the code.