-
String Problem
creation of *text[] =
char* text[9][201]={
"This is a test",
"t3.",
"hi."
};
alltext is described as : char *AllText[1][1];
in constructor : (passed *text[])
for(int i=0; i<vlen; i++){
AllText[i][0]=new char[slen+1];
strcpy(AllText[i][0], text[i]);
cout<<AllText[i][0]<<endl;
}
In the display function :
for(int i=0; i<vlen; i++)
cout<<AllText[i][0]<<endl;
-------------------------------------------
OUTPUT:
This is a test
t3.
hi.
This is a test
xxx - crash here - xxx
---------------------------------------------
**CRASH WHEN GOING TO AllText[1][0]**
(first line prints fine)
-
Try increasing the array size:
Code:
char *AllText[9][1];
-
AllText[1][1];
is an array with exactly one field: AllText[0][0].
The numbers in brackets are supposed to give the arrays size. If you want it to contain 2x2 fields, it should be AllText[2][2].