for loop and array problem

This is a discussion on for loop and array problem within the C Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    10

    Question 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
    Last edited by massimo84; 12-03-2007 at 10:37 AM.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    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.

    [edit]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]
    Last edited by hk_mp5kpdw; 12-03-2007 at 10:32 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    10
    e and am arrays are global variables..just look the variables that being used in this for loop.

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    If I were your instructor, I would fail you with this code, whether it worked or not.

    Todd

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    10
    i didn't put the whole code,just the part i thought that is needed.sorry if i am mistaken....

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    What types are your global arrays?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,456
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21