Thread: compilation error

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    92

    Unhappy compilation error

    getting compilation error in this code.....

    Code:
    #include <stdio.h>
    
    void func(int mat1[8][8],int mat[10][10][10][10]);
    
    int main()
    
    {
    
    static int mat1[10][10],mat[10][10[10][10];
    
    
    for(int call=0;call<20;call++)
    
    {
    
    for(int i=0;i<8;i++)
    
        for(int j=0;j<8;j++)
    
    {
    
      mat1[i][j]=i+j;
    
    }
    
    	func(mat1,mat);
    
    }
    
    
    
    }
    
    
    
    void func(int mat1[8][8],int mat[10][10][10][10])
    
    {
    
       static int i=0;
    
       static int j=0;
    
     if(j==10) { j = 0; i=i+1;}
    
    	for(int k1=0;k1<8;k1++)
    
    	    for(int k2=0;k2<8;k2++)
              
    		{
                    mat[i][j][k1][k2] = mat1[k1][k2];
    
              }
    
    
               j= j+1;
    
    
    
      }
    
    errors.........
    
    Compiling...
    bbc.cpp
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(676) : error C2109: subscript requires array or pointer type
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(676) : error C2109: subscript requires array or pointer type
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(676) : error C2143: syntax error : missing ']' before ';'
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(676) : error C2057: expected constant expression
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(676) : error C2466: cannot allocate an array of constant size 0
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(676) : error C2087: '<Unknown>' : missing subscript
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(693) : error C2664: 'func' : cannot convert parameter 1 from 'int [10][10]' to 'int [][8]'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    D:\Program Files\Microsoft Visual Studio\MyProjects\bbc\bbc.cpp(699) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    Error executing cl.exe.
    
    bbc.obj - 7 error(s), 1 warning(s)
    how can i remove this compilation error????
    blue_gene

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Perhaps you meant the following.
    Code:
    static int mat1[8][8],mat[10][10][10][10];
    And this is the C board, not C++.


    [edit=me]
    >[EDIT]I swear I didn't copy you Dave...

    [/edit]
    Last edited by Dave_Sinkula; 01-06-2004 at 11:53 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I thought this would be visually educational...
    Code:
    #include <stdio.h>
    
    void func(int mat1[8][8], int mat[10][10][10][10]);
    
    int main()
    {
        static int mat1[8][8], mat[10][10][10][10];
    
        for (int call = 0; call < 20; call++)
        {
    
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    mat1[i][j] = i + j;
                }//for
            }//for
    
            func(mat1, mat);
        }//for
    
        return 0;
    }//main
    
    void func(int mat1[8][8], int mat[10][10][10][10])
    {
        static int i = 0;
        static int j = 0;
    
        if (j == 10) 
        { 
            j = 0; 
            i = i + 1;
        }//if
    
        for (int k1 = 0; k1 < 8; k1++)
        {
            for (int k2 = 0; k2 < 8; k2++)
            {
                mat[i][j][k1][k2] = mat1[k1][k2];
            }//for
        }//for
    
        j = j + 1;
    }//func
    [EDIT] I swear I didn't copy you Dave...

    gg

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    92
    ohhhh.......yes yes . thanks
    blue_gene

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM