找到你要的答案

Q:Syntax in structures [c]

Q:结构中的语法[C]

I was doing a Bingo - type project when i started to get some errors in my first "for" loop and in the end of the "bingo" structure.

Can someone tell me what have I done wrong?

struct bingo{
    int table[5][5];

    int i;
    int j;
    for (i = 0; i < 25; i++)
    {
        *(table + i) = rand()%75 + 1;
        for (j = 0; j < 25; j++)
        {
            if ((j != i) && ((*(table + i)) == (*(table + j))))
            {
                i--;
                j = 5 * 5;
            }

        }


    }
};

errors: 1 IntelliSense: expected a type specifier ( first for) 2 IntelliSense: expected an identifier (end of the sturct)

我正在做一个宾果类型的项目,当我开始在我的第一个“为”循环和结束的“宾果”结构得到一些错误。

谁能告诉我我做错了什么?

struct bingo{
    int table[5][5];

    int i;
    int j;
    for (i = 0; i < 25; i++)
    {
        *(table + i) = rand()%75 + 1;
        for (j = 0; j < 25; j++)
        {
            if ((j != i) && ((*(table + i)) == (*(table + j))))
            {
                i--;
                j = 5 * 5;
            }

        }


    }
};

errors: 1 IntelliSense: expected a type specifier ( first for) 2 IntelliSense: expected an identifier (end of the sturct)

answer1: 回答1:

Structs are only able to contain variables, they can't have any logic in them. In C++ you can have functions defined in structs, but even then you need a function header and body.

结构是唯一能够控制的变量,他们不能在他们有任何逻辑。在C++中可以定义结构中的功能,但你需要一个函数头和身体。

c  data-structures