Answer the question
In order to leave comments, you need to log in
Indexes in in turn into array cells?
Hi all.
Something rigidly stupid and I can not implement the following:
I have a cycle and there is a two-dimensional array. From that it is necessary to write down in the first.
Now it looks like this:
for (int i = 0; i < countInd; i++)
{
ind[i] = new int[3];
/* тут код заполнения массива который выше */
index[i == 0 ? i : i * 3] = ind[i][0];
index[i == 0 ? i + 1 : i * 4] = ind[i][1];
index[i == 0 ? i + 2 : i * 5] = ind[i][2];
char str[256];
sprintf(str, "array %d %d %d - %d %d %d\r\n", i == 0 ? i : i * 3, i == 0 ? i + 1 : i * 4, i == 0 ? i + 2 : i * 5, ind[i][0], ind[i][1], ind[i][2]);
Log::Write(str);
}
array 0 1 2 - 0 1 2
array 3 4 5 - 0 2 3
array 6 8 10 - 0 5 4
array 9 12 15 - 0 1 5
array 12 16 20 - 1 5 2
array 15 20 25 - 6 5 2
array 18 24 30 - 6 2 7
array 21 28 35 - 7 2 3
array 24 32 40 - 7 3 0
array 27 36 45 - 7 0 4
array 30 40 50 - 4 5 6
array 33 44 55 - 6 7 4
Answer the question
In order to leave comments, you need to log in
You need to replace with , and with .
A general example of accessing an array by a single index. In this case, there is no need to check "i" for "0".i * 4
i * 3 + 1
i * 5
i * 3 + 2
int count = 3; // Количество столбцов в двумерном массиве
int row = 2; // Номер строки в двумерном массиве
int col = 2; // Номер столбца в двумерном массиве
index[row * count + col] = 10;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question