Transposing a matrix

Posted by ZaZu on Stack Overflow See other posts from Stack Overflow or by ZaZu
Published on 2010-05-09T23:14:33Z Indexed on 2010/05/09 23:18 UTC
Read the original article Hit count: 290

Filed under:
|
|

Hello,

I want to transpose a matrix, its a very easy task but its not working with me :

int testtranspose(testing *test,testing *test2){
  int i,j;
  (*test2).colsmat2=(*test).rowsmat1;
  (*test2).rowsmat2=(*test).colsmat1
  for(i=0;i<(*test).rowsmat1;i++){
    for(j=0;j<(*test).colsmat1;j++){
      ((*test2).mat[i][j])=((*test).mat[i][j]);
    }
    printf("\n");
  }
}

I thought this is the correct method of doing it, but apparently for a matrix such as :

1 2
3 4
5 6
7 8

I get :

1 2 0 0
3 4 0 0

What is the problem ?

Please help, Thanks !

© Stack Overflow or respective owner

Related posts about c

    Related posts about matrix