-
2-D dynamic array
Hi guys, I am trying to create a 2d dynamic array with the code:
Code:
char **Split_Text;
Split_Text = new *char[Vigenerek.value]; // new dynamic array
for(i=0;i<Vigenerek.value;++i) Split_Text[i] = new char[ArrayLen];
but digital mars keep giving me "need explicit cast to convert from int ** to char **. I don't really get what is it saying since i don't have a single int pointers. can somebody please help me?
-
Can you put those 3 lines, and a minimal amount of support lines necessary to create a complete compilable program (it doesn't have to do anything), and post that.
Certainly looks pretty odd to me though, as you say, no obvious sign of an int.
-
I don't have much experience with dynamic arrays but can't you just say
Code:
char *x[WIDTH];//array of pointers to chars (one for each column)
for(i=0;i<WIDTH;++i)
x[i] = new char[HEIGHT];
-
Code:
char **Split_Text;
Split_Text = new *char[Vigenerek.value]; // new dynamic array
for(i=0;i<Vigenerek.value;++i) Split_Text[i] = new char[ArrayLen];
That * is in the wrong place, it needs to be:
Code:
char **Split_Text;
Split_Text = new char*[Vigenerek.value]; // new dynamic array
for(i=0;i<Vigenerek.value;++i) Split_Text[i] = new char[ArrayLen];
-
-
May-be there's a reason why you need an array of char arrays, but to get things done a much simpler way is:
Code:
#include <vector>
#include <string>
int main()
{
std::vector<std::string> Split_Text; //voilà
// or to set memory aside out-front:
std::vector<std::string> Split_Text(Vigenerek.count, std::string(ArrayLen));
}
-
Thanks guys, thats very helpful