I need to convert a string to 2d array (character table). I can do it in main function, but I need to create a function that does the same. Here's working code in main function:
string text= "Some_text_string";
//Here, I set rows and cols manually, but i want to get a "rubber" array later
int rows = 4, cols = 5;
char table[rows][cols];
int l = 0;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
table[i][j] = text[l];
l++;
}
}
That gives me correct result, but i wanna do it like that:
table = MySuperFunction(text);
The case is to create and call a function that converts text string to an array (in fact I need a table with charachers). After that i want to rotate this table (transponate and other stuff) Maybe char array is not the best choice? so can you help me solve that?
I tried to create a function with *char
type like char* func(string input)
, pulling my code inside and return char array but i realize thats stupid. I really cannot understand how do pointers works yet so please be patient.