我有3个大整数组,我想添加到数组的不同行。这些整数定义如下:
#define APARTMENT1_USAGES {0.000, 0, 0, 0, 0, 0, 0, 0, 0, 0.189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.074, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.111, 0, 0, 0.000, 0, 0, 0, 0, 0, 0.065, 0.167, 0, 0, 0, 0.048, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0}
#define APARTMENT2_USAGES {0, 0, 0, 0, 0, 0, 0, 0.130, 0, 0, 0, 0, 0, 0.176, 0, 0.125, 0, 0.000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.161, 0.000, 0.039, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0.000, 0.109, 0, 0.032, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.152, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0.135, 0, 0, 0, 0, 0, 0, 0, 0, 0.100, 0, 0, 0.063, 0, 0, 0, 0, 0.000, 0, 0.025, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0.000, 0, 0, 0, 0, 0, 0.378, 0, 0.147, 0.229}
#define APARTMENT3_USAGES {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0, 0, 0, 0, 0, 0.000, 0, 0, 0, 0.01, 0.01, 0.02, 0.03, 0.03, 0, 0, 0, 0, 0.088, 0, 0}
我缩短了这些只是为了表明这个想法,它们通常是30x24元素。 我想要做的是将这些中的每一个加载到一个2D数组的行中,但是在没有解释的情况下得到语法错误。我尝试过如下:
double apartmentUsage[3][30*24];
apartmentUsage[1][30*24] = APARTMENT1_USAGES;
apartmentUsage[2][30*24] = APARTMENT2_USAGES;
apartmentUsage[3][30*24] = APARTMENT3_USAGES;
答案 0 :(得分:0)
您遇到的一个错误如下:
如果您定义array[3]
,则可以在array[0]
,array[1]
和array[2]
中存储三个值。
在你的代码中。它定义为apartmentUsage[3][..]
,但以1
开头。
应该是这样的 -
int multiply=30*24;
apartmentUsage[0][multiply] = APARTMENT1_USAGES;
apartmentUsage[1][multiply] = APARTMENT2_USAGES;
apartmentUsage[2][multiply] = APARTMENT3_USAGES;
**BUT**
这也不能完全解决你的问题。尝试在初始化本身中按照评论中的指示进行 -
double apartmentUsage[3][multiply] = {APARTMENT1_USAGES, APARTMENT2_USAGES, APARTMENT3_USAGES};