I'm looking at two lines of code that somebody wrote and there is an exception in the 2nd one, however I don't understand why.
char** array = (char**) new char [2] [6];
std_strlprintf(array[0],6,"[%d]", num);
std_strlprintf is a Brew function that writes formatted output to a string. (num is an integral value which is 0)
Why is there an exception with this code, what's wrong with accessing the first elelment of the array as buff[0]?
EDIT: sorry there was a typo in my initial posting. Its corrected now. THis is the code that has the exception.
Two-dimensional array is not the same as array of pointers.
Your first statement creates two arrays of six chars each as a single memory block. Replace that statement with:
and you'll be all set with your second statement. Don't forget to
Edit 0:
Huh, I should've known :) To your question in the comment:
You don't. Not in this form. If you are building a list of parameters to some C API like
execve(2)
, you have to go all the way with two-stage initialization: