Run-Time Check Failure #2 - Stack around the variable 'aux' was corrupted.

cant find my error :S
Run-Time Check Failure #2 - Stack around the variable 'aux' was corrupted.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
using namespace std;

bool TestaSeCapicua(int num);

int main()
{
	int num, certo;
	cout << "enter number with 6 digits: ";
	cin >> num;
	TestaSeCapicua(num);
	if (TestaSeCapicua(num)==3) cout << "the number is palindrome" << endl;
	else cout << "the number its no palindrome" << endl;
	system("pause");
	return 0;
}

bool TestaSeCapicua(int num)
{
	int aux[6], certo=0;
	for (int i=0; i<=6; i++)
	{
		aux[i] = num % 10;
		num /= 10;
	}
	for (int i=0; i<=3; i++)
	{
		for (int j=6; j==3; j--)
		{
			if (aux[i]==aux[j])
			{
				certo = certo + 1;
				return certo;
			}
			else 
				{
						return 0;
						break;
			}
		}
	}
}
for (int i=0; i<=6; i++) // here you are looping 7 times?
for the division of the number , thats fine, but 'aux' gives me problems
wait...
Last edited on
why? i cant understand. :s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
using namespace std;

int TestaSeCapicua(int num);

int main()
{
	int num;
	cout << "enter number with 6 digits: ";
	cin >> num;
	TestaSeCapicua(num);
	if (TestaSeCapicua(num)==3) cout << "the number is palindrome" << endl;
	else cout << "the number its no palindrome" << endl;
	system("pause");
	return 0;
}

int TestaSeCapicua(int num)
{
	int aux[6] = {0};

	int certo=0;

	for (int n=0; n<=5; ++n)
	{
		aux[n] = num % 10;
		num /= 10;
	}

	for (int i=0; i<=3; ++i)
	{
		for (int j=6; j!=3; --j)
		{
			if (aux[i] == aux[j])
			{
				certo = certo + 1;
				return certo;
			}
			else 
			{
				return 0;
				break;
			}
		}
	}
	return 0;
}
the code, isnt working, it gives me always the same result.
"the number its no palindrome"
simply your loop should be declared correctly..

1
2
3
4
5
6
int Iarray[5] = {0};

for (int i=0; i<=5; i++) //this is wrong,,, here you are looping 6 times consider 0
{
   Iarray[i] = i +1;
}


hmm limme check it again cuz i thought you wanted aux to be fixed
Last edited on
Topic archived. No new replies allowed.