-1

I am multiplying matrices and its throwing undefined reference to function transpose(.....) Please tell me where I am wrong. I know my code is messy but I am preparing for midterms that's why I am in rush and keep editing on same file maybe that's why I can't find an error

here is my code:

     #include<iostream>
   #include<fstream>
   using namespace std;
   void transpose(int arr[][10],int trans[][10],int ar[][1],int,int);
   void output(int,int);
   int main()
   {
    int array[10][10]={0};
    int trans[10][10]={0};
    int array5[3][1]={4,5,6};

    ifstream input("matrix.txt");
    int rows=0,col=0,num=0;
    char ch;
    int x=0,z=0;
    //Finding Numbers of rows and columns

        for(col=0;ch!='\n';col++)
        {
            input>>array[0][col];
            input.get(ch);

        }
        input.close();
        ifstream input1("matrix.txt");
        while(!input1.eof())
        {

            input1>>array[z][x];
            input1.get(ch);

            if(ch=='\n')
            {
            rows++;
            z++;
            }
            x++;

        }
        rows=rows+1;
        cout<<"Oye"<<rows<<" "<<col<<endl;;


        input.close();

        ifstream srch("matrix.txt");
            for(int r=0;r<rows;r++)
            {
            for(int c=0;c<col;c++)
            {
                srch>>array[r][c];
                cout<<array[r][c]<<" ";




            }
            cout<<endl;
        }
        cout<<endl<<endl;


        cout<<"=================================================" <<endl;
        transpose(array,trans,array5,rows,col);
        input.close();

     }

     void transpose(int arr[][10],int trans[][10],int ar[][10],int row,int col)
     {
        int x=0,y=0,flag=0,row1=0,j=0;


            for(row1=0;row1<row;row1++)
            {
                trans[row][j]=0;
                for(j=0;j<col;j++)
                {
                    for(int k=0;k<col;k++)
                    trans[row][j]=trans[row][j]+(arr[row1][j]*ar[k][j]);

                }
            }

            for(int r=0;r<row;r++)
            {
            for(int c=0;c<col;c++)
            {

                cout<<trans[r][c]<<" ";




            }
            cout<<endl;
            }
         }
  • Try putting the entire `tranpose` function above the main function. It compiles for me that way, apart from some other error. – Lorenz Leitner Apr 03 '16 at 15:45

1 Answers1

1

Functions prototypes doesn't match.

void transpose(int arr[][10],int trans[][10],int ar[][1],int,int);
void transpose(int arr[][10],int trans[][10],int ar[][10],int row,int col)
                                                      ^^

And why you write int array5[3][1]={4,5,6};? You can just make it int array5[3]={4,5,6}; and the function will look like this:

void transpose(int arr[][10],int trans[][10],int ar[],int row,int col);
Lassie
  • 853
  • 8
  • 18