Thread: transpose matrix

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    92

    transpose matrix

    Hi, started to learn multydimensional array, trying to transponse M[4][5] into N[5][4], compiler gives me an error but I still can't fix it, if anyone could help. Here is an error:
    Code:
    error C2143: syntax error : missing ')' before ']'
    error C2059: syntax error : ')'
    Here is my code
    Code:
    #include<stdio.h>
    
    	int M[4][5]={{1,2,3,4,5},
    				{6,7,8,9,10},
    				{11,12,13,14,15},
    				{16,17,18,19,20}};
    	int N[5][4];
    
    void transposeMatrix(void)
    {
    	int a=0, b=0;
    	for(a=0 ;a<4; ++a)
    	{
    		for(b=0; b<5; ++b)
    		
    		N[b][a]=M[a][b];
    	}
    }
    	
    void displayMatrix(void)
    {
    	int a=0, b=0;
    	for(a=0; a<5; ++a)
    	{
    		printf("\n");
    		for(b=0; b<4; ++b)
    			printf("%5i", N[a]]b]);
    	}
    	printf("\n");
    }
    int main(void)
    {
    
    transposeMatrix();
    displayMatrix();
    
    }

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Notice your typo:
    Code:
    printf("%5i", N[a]]b]);
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Code:
    Notice your typo: 
    
    Code:
    printf("%5i", N[a]]b]);
    Thank you, I bet it took you couple second to see where the error was . Hope one day I could do that too.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Does your compiler not tell you the line number in error? (Yes, I did spot it with only my eye)
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Yes the compiler told me on what line error was, and I feel so stupid that I could not spot it myself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Help with matrix transpose
    By sass208 in forum C Programming
    Replies: 6
    Last Post: 12-09-2006, 02:02 AM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM