这可能听起来有点愚蠢,但我必须知道,因为我正在用C语言编写一个bingo游戏板。
#include <stdio.h>
typedef struct {
int a;
int b;
int c;
int d;
int e;
} row;
typedef struct {
row one;
row two;
row three;
row four;
row five;
} bingo_board;
void initialize_columns()
{
bingo_board board = {
.one = {1, 2, 3, 4, 5},
.two = {6, 7, 8, 9, 10},
.three = {11, 12, 13, 14, 15},
.four = {16, 17, 18, 19, 20},
.five = {21, 22, 23, 24, 25}
};
}
这个是否可能?
typedef struct { int cells[5][5]; } bingo_board;
是一种更加适合循环操作的数据结构。 - James McNellisx
的bingo_board
可以通过 x.cells[row][column] 访问。这比为每一行或每一列编写单独的情况要容易得多。使用您的实现,您必须为x.one.a
和x.four.a
编写单独的代码(您至少必须编写十个情况,每行和每列一个)。 - James McNellis