Possible Duplicate:
Passing multidimensional array to a function C
我想将 2D 结构传递给函数这是函数的原型(prototype)和定义以及函数的“typedef”。
typedef struct {
BOOLEAN valid;
event_t event_list [MAXEVS];
int num_events;
} calentry_t;
calentry_t calendar[12] [31]; // The declaration of the structure
我如何创建函数的定义,并将其传递给二维结构以及如何传递它 请有人发现我的错误
InitializeCalendar (calentry_t *calendar){
int x, y;
for(x = 0; x < 12; x ++) {
if (x==2){
for(y = 0; y <= 28; y ++){
(*calendar).calendar[x][y].valid = TRUE;
}
for (y=29; y<= 31; y++){
(*calendar[x][y]).valid = FALSE;
}
}
else if (x==4 || x==6 || x==9 || x==11){
for(y = 0; y <= 30; y ++){
(*calendar[x][y]).valid = TRUE;
}
for (y=30; y<= 31; y++){
(*calendar)[x][y].valid = FALSE;
}
}
}
}
最佳答案
void foo(calentry_t mycal[12] [31]) {
mycal[0][1].valid =1;
}
int main(void) {
foo(calendar);
printf("valid: %d\n", calendar[0][1].valid);
}
关于c - 将 2D 结构传递给 c 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12481630/