For a class project I have to make bigint take a char array and turn it into the equivalent int array. Currently the code below works fine on my test cases for "0" and "1" but not for "27". Any ideas?
1 2 3 4 5 6 7 8 9 10
bigint :: bigint (char xChar[]){
int i = 0;
for (int i = 0; i < size; i++)
bi[i] = 0;
while (xChar[i] != '\0'){
bi[i]= xChar[i] - '0';
++i;
}
}
In bigint implementations, bi[0] is the least significant digit (ones place).
As you're parsing xChar, you're placing the most significant digit in bi[0].
@madmuse
What value does i have on line 5? And on line 6?
@AbstractionAnon
Most bigint implementations do that. My own do that. But it really makes little difference. Wait until it does to complain about it before side-tracking the OP. (As it stands, it appears his bigint is a fixed-size, making order a doubly non-issue.)
@Drakon
Numbers are made with digits, not letters in the alphabet. Also, '25' is made up of two digits, not one.