This may sound somewhat stupid, but I have to know as I'm writing a bingo board in C.
#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}
};
}
Is this possible?
typedef struct { int cells[5][5]; } bingo_board;is a much more loop-friendly data structure.bingo_boardnamedxcan be accessed as x.cells[row][column]. This is much easier to handle in a loop than having to write separate cases for each row or column. With your implementation, you have to write separate code forx.one.aandx.four.a(you have to write at least ten cases, one for each row and column).