【发布时间】:2012-02-18 17:06:27
【问题描述】:
我的问题很难描述,我有两张分别包含很多数字的表格;对于一张表,我通过索引搜索格式
table1 index format
+------+----+
|0~19 | 0 |
| | |
+------+----+
|20~29 | 1 |
| | |
+------+----+
|30~39 | 2 |
| | |
+------+----+
table2 index resource(f,t0,t1,t2)
0 1 2 3 (configure type)
+----+-----------+---------+---------+
|0 | (0,1,0,2) |(0,1,0,1)|(0,1,0,0)|
+----+-----------+---------+---------+
|1 | (0,2,0,2) |(0,2,0,1)|(0,2,0,0)|
+----+-----------+---------+---------+
|-- | (0,0,1,2) |(0,0,1,1)|(1,0,0,0)|
+----+-----------+---------+---------+
|19 | (0,0,0,0) |(0,0,0,0)|(0,0,1,1)|
+----+-----------+---------+---------+---------+
|-- | (0,0,0,2) |(0,0,0,1)|(0,0,1,0)|(0,2,1,0)|
+----+-----------+---------+---------+---------+
|29 | (0,1,0,2) |(0,1,0,1)|(0,1,0,1)|(0,1,0,1)|
+----+-----------+---------+---------+---------+
希望下面的代码sn-p能让我理解,
typedef struct my_struct {
int f;
int t0;
int t1;
int t2;
} my_struct;
// for index 0 ~ 19, the following is code snippet
my_struct format0[2][3] = {
{{0, 1, 0, 2}, {0, 1, 0, 1},{0, 1, 0, 0}}, // index 0
{{0, 2, 0, 2}, {0, 2, 0, 1},{0, 2, 0, 0}} // index 1
};
// for index 20 ~ 29, the following is code snippet
my_struct format1[1][4] = {
{{0,0,0,2},{0,0,0,1},{0,0,1,0},{0,2,1,0}} // index 20
};
我有多个二维数组,其中包含按format 分组的资源,每个数组对于不同的format 有不同的维度,按index 排列,按configure type 分类,如0、1、2..6,所以我想要将它们放入另一个一维数组中,以便通过索引轻松查找,并最终获取资源,但我不知道如何。
我尝试了以下方法但失败了:
my_struct* group[] = {
format0,
format1
};
然后使用group[0],我可以得到format0,但我发现它忘记了我需要知道的[1][2],所以我想知道有什么解决方案可以帮助我做到这一点?
【问题讨论】:
-
你的format0初始化错误,my_struct format0[1][2] = {{0, 1}};
-
每个数组的维度如何?我的意思是你从哪里得到它们?
-
嗨 TAMER,我有一张桌子,里面有很多数字,它们之间有内在的关系,尺寸是从那张桌子上得到的