c - 期待结构指针,但得到结构和反向

时间:2016-09-02 12:10:29

标签: c pointers gcc struct

我试图从main调用函数“play game”,玩游戏有输入类型'struct player'。但是,我收到了错误:

game.h:18:17: note: expected ‘struct player *’ but argument is of type ‘struct player’
struct player * play_game(struct player * first, struct player * second);
reversi.c:47:4: error: incompatible type for argument 1 of ‘play_game’
*winner = play_game( first , second );

错误被抛出参数2。

当我将参数类型切换为指针时,我得到:

reversi.c:47:12: error: incompatible types when assigning to type ‘struct player’ from type ‘struct player *’
*winner = play_game( first , second );

我环顾四周,但似乎并没有多少,而且它通常与.h文件本身有关,而我几乎可以肯定错误必须涉及到这一行:“* winner = play_game ( 第一秒 );” (这里提供的其他行)

我也试过改变所有的指针,即使它已经发挥作用,我会失败,但除了得到相同错误的变化之外没有任何地方。

我已经修改了代码以便发布,但它仍然会产生相同的错误。

#include <stdio.h>
#include <stdlib.h>

#define NAMELEN 20

struct player * play_game(struct player * first, struct player * second) ;

enum cell
{
        BLANK, RED, BLUE
};

struct player
{
    char name[NAMELEN + 1];
    enum cell token;
    unsigned score;
};

int main(void)
{
    struct player first, second, *winner = NULL;
    enter code here
    *winner = play_game( first , second );

    return EXIT_SUCCESS;
}


struct player * play_game(struct player * first, struct player * second) 
{

    return first;

}

提前感谢您提供任何帮助。

2 个答案:

答案 0 :(得分:1)

函数调用必须看起来像

winner = play_game( &first , &second );

答案 1 :(得分:0)

您已将该函数定义为将参数作为引用调用。因此,您需要使用参数call by reference调用该函数。

@Path("/isRegistered")
@GET
@Produces("application/json")
@OAuthSecurity(enabled = true)
@ApiOperation(value = "Check if a phone number is registered",
        notes = "Check if a phone number is registered",
        httpMethod = "GET",
        response = Boolean.class
)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK",
                response = String.class),
        @ApiResponse(code = 401, message = "Not Authorized",
                response = String.class),
        @ApiResponse(code = 500, message = "Cannot check if phone number is registered",
                response = String.class)
})

public Boolean isRegistered() {
    //Getting client data from the security context
    ClientData clientData = securityContext.getClientRegistrationData();
    if (clientData == null) {
        throw new InternalServerErrorException("This check allowed only from a mobile device.");
    }

    String number = clientData.getProtectedAttributes().get(SMSOTPSecurityCheck.PHONE_NUMBER);
    return number != null && !number.trim().equals("");
}

在将返回值分配到赢家变量时删除 winner = play_game( &first , &second );