Since int can hold values greater then 9 and smaller then 0, I would do only these little changes to the test code above:
Code:
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_ELEMENTS(a) ( sizeof (a) / sizeof (a)[0] )
int main( void )
{
// Now, any size is allowed.
static const unsigned int digits[] = { 1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6, 7, 8, 8, 9, 0 };
unsigned int counter[10] = {0};
unsigned int i;
for ( i = 0; i < ARRAY_ELEMENTS(digits); i++ )
{
if ( digits[i] > 9 )
{
fprintf( stderr,
"ERROR: Wrong value at position %u: %u. Only 1 digit values allowed.\n",
i, digits[i] );
return EXIT_FAILURE;
}
counter[digits[i]]++;
}
puts( "Digits count:\n"
"--------------" );
for ( i = 0; i < ARRAY_ELEMENTS( counter ); i++ )
printf( "%u: %u\n", i, counter[i] );
return EXIT_SUCCESS;
}