warning: passing arg 1 of `printArray' from incompatible pointer type

This is a discussion on warning: passing arg 1 of `printArray' from incompatible pointer type within the C Programming forums, part of the General Programming Boards category; When I try to compile my code I get this message Code: fig06_21.c: In function `main': fig06_21.c:12: warning: passing arg ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    182

    warning: passing arg 1 of `printArray' from incompatible pointer type

    When I try to compile my code I get this message

    Code:
    fig06_21.c: In function `main':
    fig06_21.c:12: warning: passing arg 1 of `printArray' from incompatible pointer type
    fig06_21.c:15: warning: passing arg 1 of `printArray' from incompatible pointer type
    fig06_21.c:18: warning: passing arg 1 of `printArray' from incompatible pointer type
    I copied the example straight from the book I have no idea what the problem is. I imagine it has something to do with the arrays.


    Code:
    #include <stdio.h>
    
    void printArray( const int[][ 3 ] );
    
    int main()
    {
       int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } },
           array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 },
           array3[ 2 ][ 3 ] = { { 1, 2}, { 4 } };
    
       printf("Values in array1 by row are:\n");
       printArray( array1 ); 
    
       printf("Values in array2 by row are:\n");
       printArray( array2 );
    
       printf("Values in array3 by row are:\n" );
       printArray( array3 );
    
       return 0;
    }
    
    
    
    void printArray( const int a[][ 3 ] )
    {
       int i, j;
    
       for (i = 0; i <= 1; i++ ) {
          for (j = 0; j <= 2; j++)
             printf("%d ", a[ i ][ j ] );
    
       printf("\n");
       }
    }

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Code:
    #include <stdio.h>
    
    void printArray(const int [][3] );
    
    int main()
    {
       const int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } };
       const int array2[ 2 ][ 3 ] = { { 7, 8, 9 }, { 10, 11, 12 } };
       const int array3[ 2 ][ 3 ] = { { 13, 14, 15 }, { 16, 17, 18 } };
    
       printf("Values in array1 by row are:\n");
       printArray( array1 ); 
    
       printf("Values in array2 by row are:\n");
       printArray( array2 );
    
       printf("Values in array3 by row are:\n" );
       printArray( array3 );
    
       getchar();
       return 0;
    }
    
    
    
    void printArray(const int a[][3] )
    {
       int i, j;
    
       for (i = 0; i <= 1; i++ ) {
          for (j = 0; j <= 2; j++)
             printf("&#37;d ", a[ i ][ j ] );
    
       printf("\n");
       }
    }
    
    /* my outout
    Values in array1 by row are:
    1 2 3
    4 5 6
    Values in array2 by row are:
    7 8 9
    10 11 12
    Values in array3 by row are:
    13 14 15
    16 17 18
    
    */
    ssharish2005

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    182
    I haven't tried running this yet(compiler on different computer) but what did you change exactly?

    All I see is that you added more numbers into one of the arrays, and added getchar to the end.

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Well you never mentioned datetype of the array, since there was type conversion conflict that is from int to const int, i changed everything to const int.

    The main problem was to declare the datatype for your array, which you dint do.
    Code:
    int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } };
    int array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 };
    int array3[ 2 ][ 3 ] = { { 1, 2}, { 4 } };
    ssharish2005

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    182
    ahh, thank you

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    182
    Your code worked, but I don't see why mine didn't. In a previous exercise I had no problem passing a normal array as a constant input. What's the difference between what I posted earlier and this?


    Code:
    #include <stdio.h>
    #define SIZE 99
    
    void mean( const int [] );
    void median( int [] );
    void mode( int [], const int [] ) ;
    void bubbleSort( int [] );
    void printArray( const int[] );
    
    
    int main()
    {
       int frequency[ 10 ] = { 0 };
       int response[ SIZE ] =
          { 6, 7, 8, 9, 8, 7, 8, 9, 8, 9,
            7, 8, 9, 5, 9, 8, 7, 8, 7, 8,
            6, 7, 8, 9, 3, 9, 8, 7, 8, 7,
            7, 8, 9, 8, 9, 8, 9, 7, 8, 9,
            6, 7, 8, 7, 8, 7, 9, 8, 9, 2,
            7, 8, 9, 8, 9, 8, 9, 7, 5, 3,
            5, 6, 7, 2, 5, 3, 9, 4, 6, 4,
            7, 8, 9, 6, 8, 7, 8, 9, 7, 8,
            7, 4, 4, 2, 5, 3, 8, 7, 5, 6,
            4, 5, 6, 1, 6, 5, 7, 8, 7 };
    
       mean( response );
       mode( frequency, response );
    
       return 0;
    }
    
    
    void mean( const int answer[] )
    {
       int j, total = 0;
    
       printf("&#37;s\n%s\n%s\n", "********", "  Mean", "********" );
    
       for (j = 0; j <= SIZE - 1; j++ )
          total += answer[ j ];
    
       printf( "The mean is the average value of the data\n"
               "items.  The mean is equal to the total of\n"
               "all the data items divided by the number\n"
               "of data items ( %d ).  The mean value for\n"
               "this run is: %d / %d = %.4f\n\n",
               SIZE, total, SIZE, ( double ) total / SIZE );
    }
    
    
    
    void mode( int freq[], const int answer[] )
    {
       int rating, j, h, largest = 0, modeValue = 0;
    
       printf("\n%s\n%s\n%s\n",
              "*********", "   Mode", "*********" );
    
       for ( rating = 1; rating <= 0; rating++ )
          freq[ rating ] = 0;
    
       for ( j = 0; j <= SIZE - 1; j++ )
          ++freq [ answer[ j ] ];
    
       printf("%s%11s%19s\n\n%54s\n%54s\n\n",
              "Response", "Frequency", "Histogram",
              "1    1     2    2", "5    0    5    0    5");
    
       for ( rating = 1; rating <= 9; rating++ ) {
          printf("%8d%11d          ", rating, freq[ rating ] );
    
          if ( freq[ rating ] > largest ) {
             largest = freq[ rating ];
             modeValue = rating;
          }
    
          for ( h = 1; h <= freq[ rating ]; h++ )
             printf("*");
    
          printf("\n");
       }
    
       printf("The mode is the most frequent value.\n"
              "For this run the mode is %d which occured"
              " %d ties.\n", modeValue, largest );
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-21-2008, 01:15 PM
  2. Passing incompatible pointer type?
    By yougene in forum C Programming
    Replies: 9
    Last Post: 11-14-2007, 12:11 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21