Reputation: 986
I was coding a program cpp.sh/9rey
And, although I get the output from the cout functions on line 41, the values just aren't reflected in the array tables at line 68 for the second one -> SuccessiveTestArrayInt[ i ][ 1 ], although its correct for SuccessiveTestArrayInt[ i ][ 0 ] .
Are the values reflected from the cout functions on line 41 being re-written again later on?
int leng = sizeof(ContainsInitialString)/sizeof(ContainsInitialString[0]);
for (int i = 0; i <= leng; i++)
{
IterationCount=0;
//if (ChecksRight(i) == 1)
ChecksRight(i);
if (SuccessiveCheck == 1)
{
cout << "Successive Done" << endl;
SuccessiveTestArrayChar[RowCount] = { ContainsInitialString[i] };
cout << "Letters in Success-Char - [" << SuccessiveTestArrayChar[RowCount] << "]" << endl;
SuccessiveTestArrayInt[RowCount][0] = { IterationCount };
SuccessiveTestArrayInt[RowCount][1] = { i }; //Position
m++;
cout << "Letters in Success-Int repetition, position - [" << SuccessiveTestArrayInt[RowCount][0] << "]["<< SuccessiveTestArrayInt[RowCount][1] << "] - [ m = " << m << "]" << endl;
RowCount++;
i++;
i = level;
}
else
{
cout << "not Successful" << endl;
level++;
i = level;
}
}
cout << " ////////////////New part Begins here //////////////////" << endl;
int leng1 = sizeof(SuccessiveTestArrayChar)/sizeof(SuccessiveTestArrayChar[0]);
cout << "leng1 = " << leng1 <<endl;
for(int i=0;i<=5;i++)
{
cout << "[" << SuccessiveTestArrayChar[i] << "]" << endl;
}
int leng2 = sizeof(SuccessiveTestArrayInt)/sizeof(SuccessiveTestArrayInt[0]);
cout << " ////////////////SuccessiveTestArrayInt //////////////////" << endl;
for(int i=0;i<=10;i++)
{
cout << "[" << SuccessiveTestArrayInt[i][0] << "]" <<"[" << SuccessiveTestArrayInt[i][1] << "]" << endl;
}
cout << " ////////////////New part Ends here //////////////////" << endl;
void ChecksRight(int i)
{
if (ContainsInitialString[i] == ContainsInitialString[i + 1])
{
level = i;
cout << "ChecksRight Function; i =" << i << "\ti+1 = " << i+1 <<endl;
cout << ContainsInitialString[i] << " == " << ContainsInitialString[i + 1] << endl;
SuccessiveCheck = 1;
IterationCount++;
cout << "IterationCount" << IterationCount<<endl;
ChecksRight(i + 1);
}
else
{
level++;
}
}
Upvotes: 1
Views: 56
Reputation: 9619
Your array declaration reads like this:
int SuccessiveTestArrayInt[50][1];
And in lines 39, 68 and 86, you are accessing it like this:
SuccessiveTestArrayInt[RowCount][1] = { i }; //Position line 39
cout << "[" << SuccessiveTestArrayInt[i][0] << "]" <<"[" << SuccessiveTestArrayInt[i][1] << "]" << endl; // line 68
SuccessiveTestArrayInt[i][1] = SortArrayPosition[d]; // line 86
In all the above cases, you are accessing your array out-of-bounds. Since the second dimension is only 1 while declaration, you can access it via 0 only. Anything greater is out-of-bounds.
Maybe you meant to declare it as:
int SuccessiveTestArrayInt[50][2]; // note the second dimension size
Upvotes: 1