Passing from an incompatible pointer type

user10884285

I am trying to check whether a row in Sudoku is valid. So in order to do that I take the sum of all the values in that row and check whether it equals a certain amount. I have written a function that takes in two parameters: the 2D list array, and the specific row I want to check. This is my function:

void row_check(int ** array, int x)
{
    int total = 0;
    for(int i = 0; i < 9; i++)
        total = total + array[x][i];

    if (total != 45)
        printf("Row is invalid!\n");
    else
        printf("Row is valid\n");
}

This is my main()

int main()
{
    grill g2;
    init(g2);
    g2[6][1] = 5; // here we modify the value on row 6              
    row_check(g2, 6);
    display_sudoku(g2);
    return 0;
}

I expect to get a message that tells me whether the row I want to be checked is valid or invalid, but instead, I get the following

sudoku.c:56:15: warning: passing argument 1 of 'row_check' from incompatible pointer type [-Wincompatible-pointer-types]
     row_check(g2, 6);
               ^~
sudoku.c:25:6: note: expected 'int **' but argument is of type 'int (*)[9]'
 void row_check(int ** array, int x)
      ^~~~~~~~~

This is my full program:

#include <stdio.h>

typedef int grill[9][9];


void init(grill g)
{
    grill gg =  {{1, 2, 3, 4, 5, 6, 7, 8, 9},
                 {4, 5, 6, 7, 8, 9, 1, 2, 3},
                 {7, 8, 9, 1, 2, 3, 4, 5, 6},
                 {2, 3, 1, 5, 6, 4, 8, 9, 7},
                 {5, 6, 4, 8, 9, 7, 2, 3, 1},
                 {8, 9, 7, 2, 3, 1, 5, 6, 4},
                 {3, 1, 2, 6, 4, 5, 9, 7, 8},
                 {6, 4, 5, 9, 7, 8, 3, 1, 2},
                 {9, 7, 8, 3, 1, 2, 6, 4, 5}};
    int i, j;
    for (i = 0; i < 9; i++)
        for (j = 0; j < 9; j++)
            g[i][j] = gg[i][j];
    return;
}


void row_check(int ** array, int x)
{
    int total = 0;
    for(int i = 0; i < 9; i++)
        total = total + array[x][i];

    if (total != 45)
        printf("Row is invalid!\n");
    else
        printf("Row is valid\n");
}

void display_sudoku(grill g)
{
    printf("\n\t%d %d %d   %d %d %d   %d %d %d\n", g[0][0], g[0][1], g[0][2], g[0][3], g[0][4], g[0][5], g[0][6], g[0][7], g[0][8]);
    printf("\t%d %d %d   %d %d %d   %d %d %d\n", g[1][0], g[1][1], g[1][2], g[1][3], g[1][4], g[1][5], g[1][6], g[1][7], g[1][8]);
    printf("\t%d %d %d   %d %d %d   %d %d %d\n", g[2][0], g[2][1], g[2][2], g[2][3], g[2][4], g[2][5], g[2][6], g[2][7], g[2][8]);
    printf("\n\t%d %d %d   %d %d %d   %d %d %d\n", g[3][0], g[3][1], g[3][2], g[3][3], g[3][4], g[3][5], g[3][6], g[3][7], g[3][8]);
    printf("\t%d %d %d   %d %d %d   %d %d %d\n", g[4][0], g[4][1], g[4][2], g[4][3], g[4][4], g[4][5], g[4][6], g[4][7], g[4][8]);
    printf("\t%d %d %d   %d %d %d   %d %d %d\n", g[5][0], g[5][1], g[5][2], g[5][3], g[5][4], g[5][5], g[5][6], g[5][7], g[5][8]);
    printf("\n\t%d %d %d   %d %d %d   %d %d %d\n", g[6][0], g[6][1], g[6][2], g[6][3], g[6][4], g[6][5], g[6][6], g[6][7], g[6][8]);
    printf("\t%d %d %d   %d %d %d   %d %d %d\n", g[7][0], g[7][1], g[7][2], g[7][3], g[7][4], g[7][5], g[7][6], g[7][7], g[7][8]);
    printf("\t%d %d %d   %d %d %d   %d %d %d\n\n", g[8][0], g[8][1], g[8][2], g[8][3], g[8][4], g[8][5], g[8][6], g[8][7], g[8][8]);
    return;
}

int main()
{
    grill g2;
    init(g2);
    g2[6][1] = 5; // here we modify the value on row 6              
    row_check(g2, 6);
    display_sudoku(g2);
    return 0;
}

How do I check my row whether is valid or not

dbush

When an array is used in an expression, it decays into a pointer to its first element. This however only applies to the outermost dimension of a multidimensional array.

The type grill is defined as a int [9][9]. This is an array of size 9, whose members are an array of size 9 of type int, i.e. int [9]. So a pointer to an element of an array of type int [9][9] is int (*)[9], not int **.

Change row_check to take a parameter of type grill.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

warning passing argument 1 of " " from incompatible pointer type enabled by default

From Dev

How to fix error: passing argument 4 of 'proc_create' from incompatible pointer type

From Dev

Incompatible type from typedef defined pointer in c

From Dev

Getting context on initialization from incompatible pointer type

From Dev

standard way to solve "passing argument of function from incompatible pointer type" with function pointers parameter

From Dev

Preventing passing incompatible pointer type

From Dev

How to fix passing argument 1 of 'count' from incompatible pointer type

From Dev

error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type

From Dev

passing arg 1 of `strcspn' from incompatible pointer type

From Dev

Passing argument 4 of ‘proc_create’ from incompatible pointer type

From Dev

How to fix: initialization from incompatible pointer type

From Dev

C Warning passing argument 2 of ‘getopt’ from incompatible pointer type

From Dev

passing argument 1 of " " from incompatible pointer type

From Dev

Defining a vector of struct and passing it as pointer in C - error: initialization from incompatible pointer type

From Dev

Initialization from incompatible pointer type (pointer to a function)

From Dev

passing arg 1 of `foo' from incompatible pointer type

From Dev

c warning - passing argument 1 of ‘insert’ from incompatible pointer type

From Dev

Incompatible pointer type when passing a pointer of pointer

From Dev

warning: passing argument x of 'xyz' from incompatible pointer type

From Dev

Warning: assignment from incompatible pointer type at malloc?

From Dev

Error in creating threads. warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type

From Dev

assignment from incompatible pointer type in list program

From Dev

C pointers: Assignment from incompatible pointer type

From Dev

pointer confusion - error: passing argument 1 of ‘value’ from incompatible pointer type; note: expected ‘...’ but argument is of type ‘...'

From Dev

Getting an error in C: passing argument 1 of function from incompatible pointer type

From Dev

warning: passing argument 2 of ‘accept’ from incompatible pointer type [-Wincompatible-pointer-types]

From Dev

Passing argument 3 of ‘fgets’ from incompatible pointer type [enabled by default]

From Dev

Passing argument 2 of 'fibonacci' from incompatible pointer type

From Dev

Warning in C: passing argument from incompatible pointer type

Related Related

  1. 1

    warning passing argument 1 of " " from incompatible pointer type enabled by default

  2. 2

    How to fix error: passing argument 4 of 'proc_create' from incompatible pointer type

  3. 3

    Incompatible type from typedef defined pointer in c

  4. 4

    Getting context on initialization from incompatible pointer type

  5. 5

    standard way to solve "passing argument of function from incompatible pointer type" with function pointers parameter

  6. 6

    Preventing passing incompatible pointer type

  7. 7

    How to fix passing argument 1 of 'count' from incompatible pointer type

  8. 8

    error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type

  9. 9

    passing arg 1 of `strcspn' from incompatible pointer type

  10. 10

    Passing argument 4 of ‘proc_create’ from incompatible pointer type

  11. 11

    How to fix: initialization from incompatible pointer type

  12. 12

    C Warning passing argument 2 of ‘getopt’ from incompatible pointer type

  13. 13

    passing argument 1 of " " from incompatible pointer type

  14. 14

    Defining a vector of struct and passing it as pointer in C - error: initialization from incompatible pointer type

  15. 15

    Initialization from incompatible pointer type (pointer to a function)

  16. 16

    passing arg 1 of `foo' from incompatible pointer type

  17. 17

    c warning - passing argument 1 of ‘insert’ from incompatible pointer type

  18. 18

    Incompatible pointer type when passing a pointer of pointer

  19. 19

    warning: passing argument x of 'xyz' from incompatible pointer type

  20. 20

    Warning: assignment from incompatible pointer type at malloc?

  21. 21

    Error in creating threads. warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type

  22. 22

    assignment from incompatible pointer type in list program

  23. 23

    C pointers: Assignment from incompatible pointer type

  24. 24

    pointer confusion - error: passing argument 1 of ‘value’ from incompatible pointer type; note: expected ‘...’ but argument is of type ‘...'

  25. 25

    Getting an error in C: passing argument 1 of function from incompatible pointer type

  26. 26

    warning: passing argument 2 of ‘accept’ from incompatible pointer type [-Wincompatible-pointer-types]

  27. 27

    Passing argument 3 of ‘fgets’ from incompatible pointer type [enabled by default]

  28. 28

    Passing argument 2 of 'fibonacci' from incompatible pointer type

  29. 29

    Warning in C: passing argument from incompatible pointer type

HotTag

Archive