Thread: passing argument of incompatible pointer type- warning in the function call in main

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    4

    Exclamation passing argument of incompatible pointer type- warning in the function call in main

    Code:
    
    
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    
    
        int size_b_row1;
        int size_b_col1;
    
    
    int main(void) {
    
    
         double C[4][4] = {{1,3,5,2},{7,6,2,2},{1,2,7,3},{2,3,5,3}};
         double TC[4][4];
    
    
        transpose(C, TC);
    
    
        puts("Hello World"); /* prints Hello World */
        return EXIT_SUCCESS;
    }
    
    
    
    
      void transpose(double** matrix_t, double** matrix)
        {
    
    
        int i,j;
    
    
        /* allocate memory for matrix */
    
    
        matrix_t=(double **) malloc(sizeof(double *)*size_b_row1);
        for( i=0;i<size_b_row1;i++)
        {
            matrix_t[i]=(double *) malloc(sizeof(double*)*size_b_col1);
        }
    
    
        matrix=(double **) malloc(sizeof(double *)*size_b_row1);
        for( i=0;i<size_b_row1;i++)
        {
            matrix[i]=(double *) malloc(sizeof(double*)*size_b_col1);
        }
    
    
        //output matrix
    
    
        for(i=0;i<size_b_col1;i++)
        {
        for(j=0;j<size_b_row1;j++)
        {
            matrix_t[j][i]= matrix[i][j];
        }
    
    
        }
    
    
        //free memory
        for(i=0;i<size_b_row1;i++)
        {
        free(matrix[i]);
        }
        free(matrix);
    
    
    
    
        for(i=0;i<size_b_row1;i++)
        {
        free(matrix_t[i]);
        }
        free(matrix_t);
        } // end of main body
    Attached Files Attached Files

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should declare transpose before calling it in main.

    Oh, and your code is badly in need of proper indentation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You also shouldn't be trying to use malloc on pointers to statically allocated arrays. Memory has already been allocated for those pointers.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing argument from incompatible pointer type
    By bhdavis1978 in forum C Programming
    Replies: 5
    Last Post: 03-17-2010, 12:42 PM
  2. passing argument from incompatible pointer type
    By bgalin in forum C Programming
    Replies: 2
    Last Post: 12-06-2009, 07:14 AM
  3. Replies: 4
    Last Post: 04-21-2008, 12:15 PM
  4. Replies: 3
    Last Post: 04-15-2008, 02:16 AM
  5. Replies: 2
    Last Post: 04-11-2008, 02:42 AM

Tags for this Thread