Thread: Warning: incompatible pointer type

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    7

    Warning: incompatible pointer type

    Hey guy , i am new in here and in programming I have a problem and i need help arguently please. I have a code that uses 2D arrays the array is initiallized in the main and then the main calls a function which takes this array as an argument. Whenever i compile i get the following warning (warning: passing argument 1 of ‘Arrange’ from incompatible pointer type)and it won't work any idea how to solve this really appreciate it. thanks in advance warning: passing argument 1 of ‘Arrange’ from incompatible pointer type
    the function is defined as follows:
    Code:
    void Arrange(int array[][20],int i, int j, int array1[20], int k);
    and in the main i am calling it that way:
    Code:
    Arrange(M, 10, 20, M1, 1);

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    You should really be using pointers in function prototypes ( int **array for 3d, and *array for 2d, make sure to allocate and free properly).

    To solve your actual problem, we'd need to see what M and M1 are.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    Thanks a lot
    M1 and M2 are defined as follows:
    Code:
    int M[10][10]={
    		{1,0,0,01,0,01,01,0,0,0},
    		{2,01,0,0,0,0,0,0,0,01},
    		{3,-1,011,0,0,-2,0,0,0}};
    int M1={6};

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    I tried your way and tried to use the following
    Code:
    void Arrange(int *array[20],int i, int j, int array1[20], int k);
    int main(void)
    {
       int M[10][10]={
            {1,0,0,01,0,01,01,0,0,0},
            {2,01,0,0,0,0,0,0,0,01},
            {3,-1,011,0,0,-2,0,0,0},
            {4,0,3,1,0,0,0,01,01,0},
            {5,-2,0,-3,0,1,0,0,0,-4}};
            int M[]={6};
    .......
    
      Arrange(M, 10, 20, M1, 1);}
    but yet i got the same error
    any other idea thanks for you coorporation

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Code:
    void Arrange(int *array[20],int i, int j, int array1[20], int k);
    int main(void)
    {
       int M[10][10]
    .....
    Arrange(M, 10, 20, M1, 1);
    The array passed must be the same size M is defined as an array of 10 arrays of 10 ints, yet you try to pass an array of array of 20 ints. In your function prototype you should have
    Code:
    void Arrange(int *array[10],int i, int j, int array1[20], int k);

    Jim

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    Put this:

    Code:
    printf("M is %p\n",M );
    printf("M[10][10] is %d\n",M[10][10]);
    Just before you pass it to Arrange(M, 10, 20, M1, 1);
    and you will see what you are passing as arguments.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Quote Originally Posted by FloridaJo View Post
    Put this:

    Code:
    printf("M is %p\n",M );
    printf("M[10][10] is %d\n",M[10][10]);
    Just before you pass it to Arrange(M, 10, 20, M1, 1);
    and you will see what you are passing as arguments.

    Actually that would be undefined behavior, since M[10][10] is outside the bounds of the array. Plus it would only print one element not the entire array.

    Jim

  8. #8
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    Thanks a lot guys it worked actually Jim you was right I fixed the size and all worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How would I fix this incompatible pointer type warning
    By ogglock in forum C Programming
    Replies: 2
    Last Post: 07-11-2011, 01:17 AM
  2. [Warning] Incompatible pointer type
    By dgs012 in forum C Programming
    Replies: 5
    Last Post: 02-20-2011, 11:27 AM
  3. Incompatible Pointer Type Warning
    By kwikness in forum C Programming
    Replies: 5
    Last Post: 10-30-2007, 06:14 PM
  4. warning: assignment from a incompatible pointer type
    By enderandrew in forum C Programming
    Replies: 8
    Last Post: 09-22-2007, 04:07 AM