Integers >9999 in PIC C18
It's because the following section of code will be trying to set start to 100,000 for numbers equal to or above 10,000 which is too big for an unsigned int which is a 16-bit and can only hold 0-65535:

while (start &lt;= input)
    start *= 10;


Changing the definition to the following should fix it:

unsigned long start = 1;


Another alternative to make the code clearer is to include stdint.h so it may be defined as the following that will work across compilers:

#include &lt;stdint.h&gt;
uint32_t start = 1;