Thread: having an testing issue

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    3

    having an testing issue

    So long story short... i am new to C and in a class right now that is challenging me in a lot of areas.

    I am trying to figure out what to pass and how to test my code through the Main function. I want it to print out the numbers of my A[j][i] as i am using memory pointers but can never seem to get the code to compile... Any help would be great. (I am going to office hours today so jut trying to understand more beforehand)

    Thanks,
    Kuz

    Code:
    include <stdlib.h>
    #include <stdio.h>
    
    
    #define M 52
    
    
    typedef int Marray_t[M][M];
    
    
    
    
    void transpose(Marray_t A) 
    {
    
    
    
    
        int i,j;
        
        
        for(i=0; i<M; i++)
        {
            int *Aji = (int *)A + i;
            int *Ai = (int *)A + (M * i);
    
    
            for(j=0; j<i;j++)
            {
    
    
            
            int t = *Aji +i; // to to store the pointer of 
            *(Aji + i) = *Ai; // store the value of another pointer *Ai
            *Ai = t; // then store the value of t
            *Ai = *Ai + M; // 
    
    
    
    
            }
    
    
        }
    
    
        for(i = 0; i < M; i++)
        {
            for(j = 0; j < M; j++)
                printf("%d\t", A[i][j]);
        }
    
    
    
    
    }
    
    
    int main() // My Main function to print out the numbers in A[j][i]
    {
        int i,j;
    
    
        for(i=0; i<M; i++)
            for(j=0; j<M; j++)
            {
                printf("%d\t", A[j][i]);
                printf("\n");
    
    
                return 0;
            }
    
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What are you trying to do with that typedef?

    Where have you declared an array named A?

    Jim

  3. #3
    Registered User
    Join Date
    Oct 2016
    Posts
    3
    From what i understand is that A is coming from the typedef and transpose.

    Code:
    typedef int Marray_t[M][M];
    
    
    
    
    void transpose(Marray_t A)
    we then can call on the pointer from memory from M which has i guess mapped out 52.

    Although i dont have it in the Main function i would think it would carry over... i could be wrong in that aspect though.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    From what i understand is that A is coming from the typedef and transpose.
    Then you understand wrong, a typedef creates a type not an instance of a type.

    Although i dont have it in the Main function i would think it would carry over
    Nope, that parameter is only used inside that one function but not in main().

    Jim

    Jim

  5. #5
    Registered User
    Join Date
    Oct 2016
    Posts
    3
    got it... i figured out what you were talking about. i fixed the main to include the Marray_t A as seend in the code... it now compiles and works! Thanks for your help.

    Code:
    int main() // My Main function to print out the numbers in A[j][i]
    {
    	int i,j;
    
    
    
    
    
    
    	Marray_t A;
    	
    	for(i=0; i<M; i++)
    	{
    
    
    
    
    		for(j=0; j<M; j++)
    		{
    			printf("%d\t", A[j][i]);
    			// printf("somthing happended");
    
    
    				
    		}
    		printf("\n");
    
    
    	}
    	return 0;
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. dll testing
    By axr0284 in forum Windows Programming
    Replies: 1
    Last Post: 03-26-2006, 10:25 PM
  3. Testing Testing 123.. Oh yeah and...
    By minime6696 in forum Windows Programming
    Replies: 0
    Last Post: 08-13-2001, 09:07 AM

Tags for this Thread