我的问题很难描述,而且我有两个分别包含很多数字的表格;为一个表,我通过搜索索引格式二维数组阵列
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)|
+----+-----------+---------+---------+---------+
希望下面的代码段可以让我理解,
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
分组资源多个2D阵列,每个阵列具有用于不同尺寸不同的format
,划分为index
,由configure type
所调用,如0,1,2..6,所以我想把它们放到另一个1d数组中以便通过索引轻松查找,最后得到资源,但是我不知道怎么样。
我曾尝试以下,但失败:
my_struct* group[] = {
format0,
format1
};
然后用group[0]
,我可以得到format0
,但我觉得它忘记了[1][2]
,我需要知道,所以我想知道有一些解决方案的帮助我这样做?
您对format0的初始化错误,my_struct format0 [1] [2] = {{0,1}}; –
你如何拥有每个阵列的尺寸?我的意思是你从哪里得到他们? –
您好TAMER,我有一个桌子上有很多数字,它们之间有内在的关系,尺寸是从那张桌子上得到的 – tiplip