c - 声明末尾预期为 ';' - 重新放置结构成员点运算符

标签 c struct compiler-errors

我正在编写一个简单的说谎者骰子游戏。不幸的是,我在编译时遇到了一个问题,说应该有一个';'并指向位于我的一个函数中的结构上的点运算符。

error: expected ';' at end of declaration
    struct player p1.dice[i] = ((rand() % 6) + 1);
                    ^
                    ;

我尝试了不同类型的结构声明,但都无济于事。这是使用数组的问题吗?

/Global Variables
int amountCall;
int diceCall;
int fails;
int dice[STARTINGDICE];

//Prototypes
int diceRoll();
void playerTurn();
int playerCreator();
int diceDisplay();

typedef struct 
{
    int fails;
    int dice[STARTINGDICE];
    int amountCall;
    int diceCall;    
} 
player;

player p1;
player p2;

int diceRoll()
{
    srand(time(NULL));
    for (int i = 0; i < (STARTINGDICE - fails); i++)
    {
        player p1.dice[i] = ((rand() % 6) + 1);                <<---- Error
    }

}

最佳答案

改变

player p1.dice[i] = ((rand() % 6) + 1);

p1.dice[i] = ((rand() % 6) + 1);

关于c - 声明末尾预期为 ';' - 重新放置结构成员点运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26946754/

相关文章:

swift - 为什么属性观察器不适用于类?

qt - 无法编译源代码-没有这样的文件或目录<libpq-fe.h>

c# - 协变和泛型

c - 如何从一个词中提取 2 个字节,以及如何从 2 个字节中提取一个词(在 C 中)?

c - 段错误(核心转储)错误消息

c - 使用 fread() 将二进制文件转换为结构体时出现问题

java - 在主循环的函数参数中找不到符号?

c++ - 链接错误与编译错误

c - 函数 ‘fgetc_unlocked’ 的隐式声明,使用 gcc 5.2

ios - 如何将 UIImage、UILabel 和 UIView 内容映射到 Swift 中的字符串?