我有这样的结构:初始化
typedef struct { int mat[x][x]; int res; } graphe;
graphe g;
,我不能访问例如图矩阵
当我设置的问题:
int m[5][5]={{0,1,1,1,0},{1,0,1,1,0},{1,1,0,1,1},{1,1,1,0,1},{0,0,1,1,0}};
graphe g = { m[5][5], 5};
for(i=0;i<lignes;i++)
{
for(j=0;j<lignes;j++)
{
printf("%i ",g.mat[i][j]);
}
printf("\n");
}
printf("Res = %i ",g.res);
我有
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Res =0
通常应该是:
0 1 1 1 0
1 0 1 1 0
1 1 0 1 1
1 1 1 0 1
0 0 1 1 0
Res =5
你能帮我吗?
'graphe g = {m [5] [5],5};''m [5] [5]'这里只是一个超出界限的访问。 – dyp 2014-10-11 23:03:39
C和C++都不允许直接复制整个数组。此外,通过'= {..}'初始化允许省略大括号来初始化数组/结构成员。正如它目前所写,你只用'= {m [5] [5],5}初始化'mat'成员的前两个元素;' – dyp 2014-10-11 23:07:44