I just cannot assign string array to my char** pointer.
I have my strings in char *tempArr[12];
But I don't know how to assign them to my char** arr variable.
First, I allocate memory using: arr = (char**)malloc(numberOfElements * sizeof(char*));
Then I tried to allocate memory to each element:
arr[i] = malloc(256 * sizeof(char));
I also tried to alocate just the memory for char pointer but neither works. The result in my arr variable is 2 to 3 nonsense characters.
What could be wrong? I tried everything I was able to find and the result is either crash or nonsense content.
EDIT: Sorry I'll try to clarify it more. Background is, I am loading data from file into structs. Each struct has char** variable that is suppose to hold strings array.
In my reading code, I am using my temp array char* tempArr[12] and successfully loading strings into it. Then I pass it allong to my function that is creating my structs.
The problem starts here, I was trying to "convert" my passed array so it can be stored in char** arr variable.
arr = ...makes sense (more-so if you lose the cast, which for some odd reason you did incorrectly there, but correctly in yourarr[i] = ...assignment). If this is entirely self-contained in some function scope, it looks right. Ifchar **arris a function out-parameter, then its wrong. Post an MCVE of the REAL problem.