Char passing argument in c

tath

Im writing a game in c and i want to change player in every step. So i create i function to do this.

struct Node{
    char player[4];
    int cubesRemaining;
    struct Node *left;
    struct Node *right;
};

char *switchPlayer(struct Node *n){
    if (strcmp(n->player, "MAX") == 0){
        strcpy(n->player, "MIN");
        return (n->player);
    }
    else{
        strcpy(n->player, "MAX");
        return (n->player);
    }
}

Now i want to build the game tree and i create another function using recursion. Im also using the switchplayer function but im getting an error message.Here is my code:

struct Node *buildGameTree(int ncubes, char *player){
    struct Node *cube = calloc(1, sizeof(struct Node));
    cube->cubesRemaining = ncubes;
    strcpy(cube->player, player);

    if (cube->cubesRemaining >= 1){
        cube->left = buildGameTree(ncubes - 1, switchPlayer(cube->player));
    }
    if (cube->cubesRemaining >= M){
        cube->right = buildGameTree(ncubes - K, switchPlayer(cube->player));
    }

    return (cube);
}

The error message is: Warning passing argument 1 of switchplayer from incompatible pointer type

Eric Renouf

You define switchplayer to take a struct Node* type, but you're passing cube->player which is a char *; therefore, you are passing an incompatible pointer type.

You probably want to just pass cube and not cube->player as in

cube->left = buildGameTree(ncubes -1, switchPlayer(cube));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing a pointer to a char array as an argument to a function - C

From Dev

Passing a pointer to a char array as an argument to a function - C

From Dev

C - Opening a file and reading char by char with passing the file pointer as argument

From Dev

Passing char pointer as argument to function

From Dev

Passing char pointers in C

From Dev

Cannot convert 'const char*' to 'WCHAR*' in argument passing

From Dev

Passing 2D array of char as argument

From Dev

Passing char* as an argument prevents function from working

From Dev

Passing function char argument returns error

From Dev

C++ "error: passing 'const std::map<int, std::basic_string<char> >' as 'this' argument of ..."

From Dev

C++ "error: passing 'const std::map<int, std::basic_string<char> >' as 'this' argument of ..."

From Dev

Passing structure as argument in C function

From Dev

C++ passing a class as an argument

From Dev

passing multidimensional array as argument in C

From Dev

Passing NULL as argument to a C macro

From Dev

passing function as argument in c++

From Dev

Passing const char * to a function in C

From Dev

Char passing in C++ with pointers

From Dev

Passing const char * to a function in C

From Dev

Passing a buffer (char*) to a function in C

From Dev

expected ‘const char *’ but argument is of type ‘char **’ in C

From Dev

expected ‘const char *’ but argument is of type ‘char **’ in C

From Dev

C++ template with char[] argument

From Dev

passing a const char instead of a std::string as function argument

From Dev

Passing a Pointer as an Argument in C/C++?

From Dev

C++: Argument Passing "passed by reference"

From Java

Passing int as bool argument in C++

From Dev

Passing any generic function as a C++ argument

From Dev

Passing an event handler as argument in C#

Related Related

  1. 1

    Passing a pointer to a char array as an argument to a function - C

  2. 2

    Passing a pointer to a char array as an argument to a function - C

  3. 3

    C - Opening a file and reading char by char with passing the file pointer as argument

  4. 4

    Passing char pointer as argument to function

  5. 5

    Passing char pointers in C

  6. 6

    Cannot convert 'const char*' to 'WCHAR*' in argument passing

  7. 7

    Passing 2D array of char as argument

  8. 8

    Passing char* as an argument prevents function from working

  9. 9

    Passing function char argument returns error

  10. 10

    C++ "error: passing 'const std::map<int, std::basic_string<char> >' as 'this' argument of ..."

  11. 11

    C++ "error: passing 'const std::map<int, std::basic_string<char> >' as 'this' argument of ..."

  12. 12

    Passing structure as argument in C function

  13. 13

    C++ passing a class as an argument

  14. 14

    passing multidimensional array as argument in C

  15. 15

    Passing NULL as argument to a C macro

  16. 16

    passing function as argument in c++

  17. 17

    Passing const char * to a function in C

  18. 18

    Char passing in C++ with pointers

  19. 19

    Passing const char * to a function in C

  20. 20

    Passing a buffer (char*) to a function in C

  21. 21

    expected ‘const char *’ but argument is of type ‘char **’ in C

  22. 22

    expected ‘const char *’ but argument is of type ‘char **’ in C

  23. 23

    C++ template with char[] argument

  24. 24

    passing a const char instead of a std::string as function argument

  25. 25

    Passing a Pointer as an Argument in C/C++?

  26. 26

    C++: Argument Passing "passed by reference"

  27. 27

    Passing int as bool argument in C++

  28. 28

    Passing any generic function as a C++ argument

  29. 29

    Passing an event handler as argument in C#

HotTag

Archive