I compile with no errors, then I run this and I get a segmentation fault. When I use gdb to try debugging, I get this:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000100000000
0x0000000100000cc8 in isPal (Val=10201, Pow=4) at Palindrome.cc:53
53 S_Vals[D] = value;//Store each individual value found in the number inside the array
6: Pow = 4
4: power = 10000
3: Val = 10201
2: S_Vals = 0x100000000 "????\a"
1: value = 1
(gdb) print S_Vals
$1 = 0x100000000 "????\a"
Here is the code around where the program fails:
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
|
char* S_Vals;
char* B_Vals;
int power;
int value;
int length = 0;
for (int D = 0; Pow >= 0 && Val != 0; Pow--)
{
power = pows_n(10, Pow);
if (Val/power == 0)//
{
S_Vals[D] = 0;//This means that we have encountered a zero
D++;
continue;
}
else
{
value = (Val/power);
S_Vals[D] = value;//Store each individual value found in the number inside the array
Val = Val - (S_Vals[D] * power);
D++;
}
}
|
Help! I don't know what I am doing wrong