Converting char array into equivalent int array

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?

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';
You're storing the digits in the wrong order.

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].
The alphabet is 26 letters long.
Does it work for every number from 0 to 25? Or just 0 and 1.
Uh, did anyone read his code?

What value does i have on line 5? And on line 6?

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.)

Numbers are made with digits, not letters in the alphabet. Also, '25' is made up of two digits, not one.

Hope this helps.
Last edited on
Thank you so much AbstractionAnon. Was a very silly error on my part that I just didn't consider!
Wait.. what?

Well, glad you fixed your problem. :-S
Topic archived. No new replies allowed.