c++ - How to convert strings of 2D array into each char array? -
i taking inputs in 2d-array. i.e--
forward 50 20   i want copy "forward" in simple char array[], "50" in char array[] (each string in each char array[])
i able store first element in first array.
i've tried storing index of "space" , storing integer values until "another space "\n" found in 2d-array, stored first string (forward) in char arrays ran loop on... here's code checking on.
for (int j=0; arr[1][j] != ' '; j++) {     check[m] = arr[1][j];     m++; }  check[m] = '\0'; int k = 0; cout << check << endl;  if (arr[1][m] == ' ') {     (;arr[1][m] == ' ';)     {         m++;          cout << arr[1][m];         value[k] = arr[1][m];         k++;     }  }  value[k] = '\0';      
from comments seems though might should c question , not c++ question.
but since homework anyway maybe seeing c++11 solution moving in right direction.
const char* arr[]{"forward ", "50 ", "back ", "20"}; const string check = accumulate(cbegin(arr), cend(arr), string());   after check contain "forward 50 20".
Comments
Post a Comment