Counting digits of numbers
There's a possibility that user may enter invalid characters at input. If that's the case, subsequent calls to scanf() fail, as these characters remain in buffer of input stream, thus printing error message infinitely.


You can use construct like the one below to avoid that. It looks like this may serve you better based on the requirement.

while (true)
{
    if (scanf("%ld",&amp;input) != 1 || input &lt; 0)
    {
        fprintf(stderr,"error: invalid input\n");  /* arbitrary */
        exit(EXIT_FAILURE);
    }
    else
    {
        // rest of code 
    }
}