There is a method that parses the string of the form ширина:долгота@ширина:долгота@...@@ and fills the two-dimensional array int[x][2] :
void fillArr(String line, int **arr) { line += "@@"; int x = 0; int lng = line.length(); byte i = 0; char char_array[lng + 1]; strcpy(char_array, line.c_str()); String str = ""; arr[0] = new int[2]; while( x < lng - 1 ){ if(char_array[x] == ':' || char_array[x] == '@') { int num = str.toFloat() * 1000000; str = ""; if (char_array[x] == ':') { arr[i][0] = num; } else { arr[i][1] = num; i++; arr[i] = new int[2]; } x++; continue; } str += char_array[x++]; } } method call:
int **arr = new int *[2]; fillArr(str, arr); But after several passes (5-7 pairs of values), the program pours, what can be problematic? Didn't the whole memory of the crystal get clogged up?
int num = str.toFloat() * 1000000; - it is used for trimming non-significant digits and saving only significant
With the number of pairs up to 5-7, the program works and fills the array as expected. Ie on the output you can get something like this:
arr[0][0] - широта 1; arr[0][1] - долгота 1; arr[1][0] - широта 2; arr[1][1] - долгота 2; arr[2][0] - широта 3; arr[2][1] - долгота 3; arr[3][0] - широта 4; arr[3][1] - долгота 4; 49.46666813651794:32.06716351318357@49.47983057360329:32.08364300537107@49.46767217581145:32.106817291259745@49.45082390409025:32.11076550292967
executing code:
for (int i = 0; i < 4; i++) { Serial.print(arr[i][0]); Serial.print(" "); Serial.println(arr[i][1]); } I get:
49466668 32067166 49479832 32083644 49467672 32106820 49450824 32110768
xpointers, i.e. you haveint[2][2]instead ofint[x][2]and at 3 iterations going beyond the bounds of the array when accessingarr[i]. - VTTint[x][2]cannot be accessed using theint **pointer. You do not createint[x][2], but an "intruded" arrayint *[2]from pointers to arrays. And you always create an array of2 на 2, and notx на 2. Why always2 на 2? - AnTxappears when allocating memory for an array. You create the top level array asnew int *[2]. Subarrays are created asnew int[2]. Everywhere strictly written 2. Noxwhen creating arrays does not appear. - AnTstd::vector<std::array<int, 2>> arr, pass it by reference and add new elements to it viaarr.emplace_back(num, 0);. - VTT