结构体数组struct是不是只能定义成全局变量?
现在有一个数组叫queue[],是由一群叫Maze的结构体组成的,需要把它作为一个参数传递给一个叫test_structsarray的函数:
程序代码:
void test_structsarray(Maze queue[], int head, int tail)
{
int x_following, y_following;
x_following = queue[head].x + 1;
y_following = queue[head].y * 2;
return;
}
int main()
{
struct Maze
{
int x;
int y;
};
struct Maze queque[9];
int head = 1, tail = 1;
queque[tail].x = 0;
queque[tail].y = 0;
test_structsarray(queue, head, tail);
return 0;
}
我尝试了“test_structsarray(Maze queue[], int head, int tail)”“test_structsarray(struct Maze queue[], int head, int tail)”“test_structsarray(Maze* queue, int head, int tail)”,可是要么报错“queue was not declared in this scope”、要么报错“Maze was not declared in this scope”……
唯一一次运行没错的,是把整个struct Maze的定义放到main函数外面、作为全局变量的。但是这样无法在main里面对queque[tail].x和queque[tail].y赋值,一旦赋值又报错。
请问,我那段代码中,test_structsarray和main到底哪里写错了?
谢谢!


