So I got past my last problem using new[],
but now I seem to have a new one...
I created a char***, var.
The goal was to build each dimension of the array to be different sizes at different times,
based on separate user input...
Here is the code:
#include<iostream>
using namespace std;
int main(){
char*** var;
int ar1,*ar2,x,y,len;
char inp[80];
cout<< "var[x]: x = ";
cin>> ar1;
var=new char**[ar1];
ar2 = new int[ar1];
for(x=0;x<ar1;x++){
cout<< "var["<< x<< "][y]: y = ";
cin>> ar2[x];
var[x]=new char*[ar2[x]];
for(y=0;y<ar2[x];y++){
cout<< "var["<< x<< "]["<< y<< "]*: val = ";
cin>> inp;
len=0;
while(inp[len]!='\0'){
len++;
}
var[x][y]=new char[len + 1];
var[x][y]=inp;
}
}
cout<< "\n\nNew Array:\n";
for(x=0;x<ar1;x++){
for(y=0;y<ar2[x];y++){
cout<< " "<< x<< " , "<< y<< " = "<< var[x][y]<< endl;
}
}
return 0;
}
this is what happens:
C:\c>tsiz
var[x]: x = [b]2[/b]
var[0][y]: y = [b]2[/b]
var[0][0]*: val = [b]hello[/b]
var[0][1]*: val = [b]somevalue[/b]
var[1][y]: y = [b]3[/b]
var[1][0]*: val = [b]anothervalue[/b]
var[1][1]*: val = [b]moredata[/b]
var[1][2]*: val = [b]ofdifferentsizes[/b]
New Array:
0 , 0 = ofdifferentsizes
0 , 1 = ofdifferentsizes
1 , 0 = ofdifferentsizes
1 , 1 = ofdifferentsizes
1 , 2 = ofdifferentsizes
C:\c>
the first part seems to be working,
but when I set a value to var[x][y], it seems to change all of the values...
under New Array it should expectedly show all of the values of different lengths that I put into the array, and each spot in the array should be just large enough to hold that data.
What am I doing wrong here?
I can't seem to get the values to be set correctly...
any help is appreciated