I see I overlooked pow incrementing by *= 10. So i'm guessing this is causing integer overflow after a certain value and since it's unsigned it wraps around to zero. Since UINT_MAX is 10 integers long, i'm guessing it will perform 1010 = 10,000,000,000, which would loop around to 0 because of it's 11 integers. I'm super close to getting it, I'm just missing some small logical schema. This is my entire function:
HugeInteger *parseInt(unsigned int n)
{
HugeInteger *hugeInt;
int i, intLen = 0;
unsigned int localN = n, pow, x;
while(localN != 0)
{
localN /= 10;
++intLen;
}
hugeInt = createHugeInt();
if(hugeInt == NULL)
return NULL;
hugeInt->digits = createDigits(hugeInt, intLen);
if(hugeInt->digits == NULL)
return NULL;
localN = n;
for(pow = 1, i = 0; localN / pow > 0; pow *= 10)
{
hugeInt->digits[i++] = localN / pow % 10;
}
return hugeInt;
}
And this is its call from main where I get the errors with its declaration: HugeInteger *p; hugePrint(p = parseInt(UINT_MAX));
The associated print function:
void hugePrint(HugeInteger *p)
{
int i;
if (p == NULL || p->digits == NULL)
{
printf("(null pointer)\n");
return;
}
for (i = p->length - 1; i >= 0; i--)
printf("%d", p->digits[i]);
printf("\n");
}
Expected output for UINT_MAX argument should be: 4294967295
Again, I really appreciate any input!