hey,
Just having trouble with creating a 2d array in the heap memory.
my code goes something like this:
twoDarray = new char[iSize][iSize];
where iSize is passed into the method.
cheers,
ActionMan
This is a discussion on Just a quickie within the C++ Programming forums, part of the General Programming Boards category; hey, Just having trouble with creating a 2d array in the heap memory. my code goes something like this: twoDarray ...
hey,
Just having trouble with creating a 2d array in the heap memory.
my code goes something like this:
twoDarray = new char[iSize][iSize];
where iSize is passed into the method.
cheers,
ActionMan
ActionMan
"THE DAY IS MYNE!!!!
I'll take famouse titties for $400"
-Sean Connery, Saturday Night Live
sorry forgot to say that twoDArray is declared as follows..
char ** twoDarray;
ActionMan
"THE DAY IS MYNE!!!!
I'll take famouse titties for $400"
-Sean Connery, Saturday Night Live
You cannot do it like that. A char** is a pointer to a pointer!
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
I believe this is what you're looking for...
Code:char **NewMatrix(int rows, int columns) { char **matrix = new char*[rows]; while(rows) { matrix[--rows] = new char[columns]; memset(matrix[rows], 0, columns); } return matrix; } //...You MUST call this to free up the memory... void KillMatrix(char** matrix, int rows) { while(rows) delete [] matrix[--rows]; } int main(int argc, char *argv[]) { int i, rows = 20, cols = 50; char **strings = NewMatrix(rows, cols); for(i = 0; i < rows; i++) sprintf(strings[i], "\nString #%i", i+1); for(i = 0; i < rows; i++) { printf(strings[i]); getch(); } printf("\n\n\nDeallocating Array!"); getch(); KillMatrix(strings, rows); return 0; }
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
hey,
thanks.. that the way I origionally had it. I was hoping new was a little more advanced.
thanks for the help!!
cheers,
ActionMan