well i did the exact same thing to enter the string into the array but I wanted to create a function for putting them in the arrays, and another for summing them, in the other function there is no need to put them in an array again, i just need to sum them.
but thanks anyway.
any other ideas?
char a, int alen, // c = a + b
char b, int blen,
char c, int clen )
// It helps if alen >= blen
if (alen < blen) return sum( b, blen, a, alen, c, clen );
// Also, clen must be greater than or equal to (alen + 1)
if (clen <= alen) returnfalse;
// Now you are ready to add
int carry = 0;
// First, add the stuff that is in both arrays
for (i = 0; i < blen; i++)
// Next, keep adding carry through the longer array (a)
for (; i < alen; i++)
// Next, carry until no carry remains
if (carry != 0)
c[ clen - 1 - i ] = carry + '0';
Notice how I index the arrays as x[ xlen - 1 - i ]. Remember, you have to work from least-significant digit to most-significant.